QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#23025 | #2887. 区间矩阵乘法 | enh | WA | 706ms | 169196kb | C++14 | 1.8kb | 2022-03-11 16:08:52 | 2022-04-30 02:14:26 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std ;
#define int unsigned int
const int N = 200005 ;
int n , m , a[N] , s[200005][205] , ans[N] , v[N] ;
struct Node {
int d , p1 , p2 , id ;
} q[N] ;
inline bool cmp ( Node u , Node v ) {
return u .d < v .d ;
}
inline int cd ( int x , int nq ) {
return ( x - 1 ) / nq + 1 ;
}
inline int cm ( int x , int nq ) {
return ( x - 1 ) % nq + 1 ;
}
signed main ( ) {
cin >> n ;
for ( int i = 1 ; i <= n ; ++ i )
cin >> a [ i ] , v [ i ] = v [ i - 1 ] + a [ i ] ;
cin >> m ;
for ( int i = 1 ; i <= m ; ++ i ) {
cin >> q [ i ] .d >> q [ i ] .p1 >> q [ i ] .p2 ;
q [ i ] .id = i ;
}
sort ( q + 1 , q + 1 + m , cmp ) ;
int p = 1 ;
for ( int c = 1 ; c * c <= n ; ++ c ) {
if ( q [ p ] .d > c ) continue ;
int nc = cd ( n , c ) ;
for ( int i = 1 ; i <= c * nc ; ++ i )
s [ cd ( i , c ) ] [ cm ( i , c ) ] = a [ i ] ;
for ( int i = 1 ; i <= nc ; ++ i )
for ( int j = 1 ; j <= c ; ++ j )
s [ i ] [ j ] += s [ i - 1 ] [ j ] ;
while ( q [ p ] .d == c ) {
for ( int i = 0 ; i < c ; ++ i ) {
int w1 = cm ( q [ p ] .p1 + i , c ) , n1 = cd ( q [ p ] .p1 + i , c ) - 1 , p2 = q [ p ] .p2 ;
ans [ q [ p ] .id ] += ( s [ n1 + c ] [ w1 ] - s [ n1 ] [ w1 ] ) * ( v [ p2 + ( i + 1 ) * c - 1 ] - v [ p2 + i * c - 1 ] ) ;
}
++ p ;
}
while ( q [ p ] .d == c ) {
for ( int i = 0 ; i < c ; ++ i ) {
int w1 = cm ( q [ p ] .p1 + i , c ) , n1 = cd ( q [ p ] .p1 + i , c ) - 1 ;
int w2 = cm ( q [ p ] .p2 + i , c ) , n2 = cd ( q [ p ] .p2 + i , c ) - 1 ;
ans [ q [ p ] .id ] += ( s [ n1 + c ] [ w1 ] - s [ n1 ] [ w1 ] ) * ( s [ n2 + c ] [ w2 ] - s [ n2 ] [ w2 ] ) ;
}
++ p ;
}
}
for ( int i = 1 ; i <= m ; ++ i )
cout << ans [ i ] << "\n" ;
return 0 ;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 5704kb
input:
8 1 2 2 2 2 2 1 1 2 2 2 2 1 3 7
output:
32 2
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 706ms
memory: 169196kb
input:
200000 110569 155 159393 154631 169597 134901 75060 60085 189794 169502 10184 170809 170894 5697 83892 99814 97985 11604 39943 171446 77088 44463 60432 121559 54578 115592 151722 115322 147103 126168 55464 42044 181426 196809 58680 173065 136429 76030 109558 78475 161094 46875 1564 177386 108053 828...
output:
3827878782 2126613865 3464197503 700818946 3501766645 3135530299 3899557935 824210853 1896225959 3990534623 2125225772 106070907 3337745309 406568818 4117597926 1839070294 3713307242 1347647697 2968862403 3851729348 3404135541 3214797446 2874669120 1996889736 1244955431 4042393869 750052335 27635510...
result:
wrong answer 1st lines differ - expected: '4189305368', found: '3827878782'