Submission #82330

# Submission time Handle Problem Language Result Execution time Memory
82330 2018-10-30T02:07:32 Z wzy Lottery (CEOI18_lot) C++11
100 / 100
1488 ms 11080 KB
/*
  Fix one diagonal and use prefix sum of a boolean matrix such that the position (i,j) represents mismatch of i and j
  is better to code if the diagonal is (i , 1) - > (i+1 , 2) -> (i+2 , 3) ... 

*/

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>

int n , l , q , a[10002] , k[101] , v[10002], r[10002][101] , pos[10002] , ans[10002][101], k2[101];

int32_t main(){
	scanf("%d%d" , &n , &l);
	for(int i = 1 ; i <= n;i ++) scanf("%d" ,  &a[i]);
	scanf("%d" , &q);
	for(int i = 1 ; i <= q ;i ++) scanf("%d" , &k[i]), k2[i] = k[i];
	sort(k + 1 , k + 1 + q);
	for(int i = 1 ; i <= q; i ++) pos[k[i]] = i;
	// fix the diagonal
	v[0] = 0;
	for(int i = 1 ; i <= n; i ++){
		pii curr = pii(i, 1);
		int sz = 0;
		while(curr.F <= n && curr.S <= n){
			v[++sz] = (a[curr.F] != a[curr.S]);
			curr.F++ , curr.S++; 
		}
		curr = pii(i ,1);
		for(int j = 1 ; j <= sz; j++){
			v[j] += v[j-1];
		}
		for(int j = 1 ; j <= sz ;j ++){
			if(j>= l){
				pii cc = pii(i+j-1 , j);
				int U = v[j]-v[j-l];
				if(cc.F - l +1 == cc.S - l + 1) continue;
				int L = 1 , R = q;
				int ansj = -1;
				while(L<=R){
					int mid = (L + R)/2;
					if(k[mid] >= U){
						ansj = mid;
						R = mid - 1;
					}
					else L = mid + 1;
				}
				//cout<<cc.F - l + 1 <<" " << cc.S - l + 1 <<" " << U << " "<<ansj << " " << k[ansj] << endl;
				if(ansj != -1){
					r[cc.F - l + 1][ansj]++;
					r[cc.S - l + 1][ansj]++;
				}
			}
		}
	}
	for(int i = 1 ; i<= n; i ++){
		for(int j = 1 ; j <= q;j++){
			r[i][j] += r[i][j-1];
		}
	}	
	for(int j = 1 ; j <= q; j ++){
		for(int i = 1 ; i <= n-l+1;i ++){
			printf("%d ", r[i][pos[k2[j]]]);
		}
		printf("\n");
	}
}

Compilation message

lot.cpp: In function 'int32_t main()':
lot.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d" , &n , &l);
  ~~~~~^~~~~~~~~~~~~~~~~~
lot.cpp:19:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1 ; i <= n;i ++) scanf("%d" ,  &a[i]);
                               ~~~~~^~~~~~~~~~~~~~~
lot.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d" , &q);
  ~~~~~^~~~~~~~~~~
lot.cpp:21:51: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1 ; i <= q ;i ++) scanf("%d" , &k[i]), k2[i] = k[i];
                                ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 416 KB Output is correct
4 Correct 2 ms 424 KB Output is correct
5 Correct 2 ms 556 KB Output is correct
6 Correct 2 ms 628 KB Output is correct
7 Correct 2 ms 628 KB Output is correct
8 Correct 3 ms 856 KB Output is correct
9 Correct 3 ms 856 KB Output is correct
10 Correct 3 ms 856 KB Output is correct
11 Correct 3 ms 856 KB Output is correct
12 Correct 3 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 416 KB Output is correct
4 Correct 2 ms 424 KB Output is correct
5 Correct 2 ms 556 KB Output is correct
6 Correct 2 ms 628 KB Output is correct
7 Correct 2 ms 628 KB Output is correct
8 Correct 3 ms 856 KB Output is correct
9 Correct 3 ms 856 KB Output is correct
10 Correct 3 ms 856 KB Output is correct
11 Correct 3 ms 856 KB Output is correct
12 Correct 3 ms 856 KB Output is correct
13 Correct 31 ms 1492 KB Output is correct
14 Correct 23 ms 1628 KB Output is correct
15 Correct 19 ms 1628 KB Output is correct
16 Correct 30 ms 1796 KB Output is correct
17 Correct 27 ms 1796 KB Output is correct
18 Correct 26 ms 1812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 485 ms 4980 KB Output is correct
2 Correct 409 ms 5052 KB Output is correct
3 Correct 379 ms 5052 KB Output is correct
4 Correct 377 ms 5116 KB Output is correct
5 Correct 298 ms 5216 KB Output is correct
6 Correct 352 ms 5316 KB Output is correct
7 Correct 367 ms 5416 KB Output is correct
8 Correct 465 ms 5516 KB Output is correct
9 Correct 381 ms 5744 KB Output is correct
10 Correct 376 ms 5744 KB Output is correct
11 Correct 34 ms 5744 KB Output is correct
12 Correct 269 ms 5744 KB Output is correct
13 Correct 306 ms 5908 KB Output is correct
14 Correct 314 ms 6008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 485 ms 4980 KB Output is correct
2 Correct 409 ms 5052 KB Output is correct
3 Correct 379 ms 5052 KB Output is correct
4 Correct 377 ms 5116 KB Output is correct
5 Correct 298 ms 5216 KB Output is correct
6 Correct 352 ms 5316 KB Output is correct
7 Correct 367 ms 5416 KB Output is correct
8 Correct 465 ms 5516 KB Output is correct
9 Correct 381 ms 5744 KB Output is correct
10 Correct 376 ms 5744 KB Output is correct
11 Correct 34 ms 5744 KB Output is correct
12 Correct 269 ms 5744 KB Output is correct
13 Correct 306 ms 5908 KB Output is correct
14 Correct 314 ms 6008 KB Output is correct
15 Correct 533 ms 6108 KB Output is correct
16 Correct 355 ms 6264 KB Output is correct
17 Correct 406 ms 6264 KB Output is correct
18 Correct 374 ms 6320 KB Output is correct
19 Correct 405 ms 6408 KB Output is correct
20 Correct 383 ms 6532 KB Output is correct
21 Correct 374 ms 6676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 416 KB Output is correct
4 Correct 2 ms 424 KB Output is correct
5 Correct 2 ms 556 KB Output is correct
6 Correct 2 ms 628 KB Output is correct
7 Correct 2 ms 628 KB Output is correct
8 Correct 3 ms 856 KB Output is correct
9 Correct 3 ms 856 KB Output is correct
10 Correct 3 ms 856 KB Output is correct
11 Correct 3 ms 856 KB Output is correct
12 Correct 3 ms 856 KB Output is correct
13 Correct 31 ms 1492 KB Output is correct
14 Correct 23 ms 1628 KB Output is correct
15 Correct 19 ms 1628 KB Output is correct
16 Correct 30 ms 1796 KB Output is correct
17 Correct 27 ms 1796 KB Output is correct
18 Correct 26 ms 1812 KB Output is correct
19 Correct 485 ms 4980 KB Output is correct
20 Correct 409 ms 5052 KB Output is correct
21 Correct 379 ms 5052 KB Output is correct
22 Correct 377 ms 5116 KB Output is correct
23 Correct 298 ms 5216 KB Output is correct
24 Correct 352 ms 5316 KB Output is correct
25 Correct 367 ms 5416 KB Output is correct
26 Correct 465 ms 5516 KB Output is correct
27 Correct 381 ms 5744 KB Output is correct
28 Correct 376 ms 5744 KB Output is correct
29 Correct 34 ms 5744 KB Output is correct
30 Correct 269 ms 5744 KB Output is correct
31 Correct 306 ms 5908 KB Output is correct
32 Correct 314 ms 6008 KB Output is correct
33 Correct 533 ms 6108 KB Output is correct
34 Correct 355 ms 6264 KB Output is correct
35 Correct 406 ms 6264 KB Output is correct
36 Correct 374 ms 6320 KB Output is correct
37 Correct 405 ms 6408 KB Output is correct
38 Correct 383 ms 6532 KB Output is correct
39 Correct 374 ms 6676 KB Output is correct
40 Correct 975 ms 7412 KB Output is correct
41 Correct 276 ms 7412 KB Output is correct
42 Correct 715 ms 7532 KB Output is correct
43 Correct 662 ms 7532 KB Output is correct
44 Correct 657 ms 7532 KB Output is correct
45 Correct 1488 ms 10796 KB Output is correct
46 Correct 283 ms 10796 KB Output is correct
47 Correct 1175 ms 11080 KB Output is correct
48 Correct 827 ms 11080 KB Output is correct
49 Correct 793 ms 11080 KB Output is correct