QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#23026#2887. 区间矩阵乘法enhWA 663ms169292kbC++141.4kb2022-03-11 16:10:072022-04-30 02:14:28

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 02:14:28]
  • 评测
  • 测评结果:WA
  • 用时:663ms
  • 内存:169292kb
  • [2022-03-11 16:10:07]
  • 提交

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 ;
		}
	}
	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: 2ms
memory: 7668kb

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: 663ms
memory: 169292kb

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'