Submission #114923

# Submission time Handle Problem Language Result Execution time Memory
114923 2019-06-04T02:53:12 Z user202729 Lottery (CEOI18_lot) C++17
100 / 100
348 ms 8312 KB
#include<iostream>
#include<vector>
#include<algorithm>

#ifdef _GLIBCXX_DEBUG
#define cin cin_
#include<sstream>
namespace std{
	stringstream cin(R"(
	6 2
	1 2 1 3 2 1
	2
	1
	2
	)");}
#endif

int main(){
	std::ios::sync_with_stdio(0);std::cin.tie(0);
	int nn,len;std::cin>>nn>>len;
	std::vector<int> a(nn);for(int& x:a)std::cin>>x;

	int nq;std::cin>>nq;
	struct Query{
		int n,ind;
		std::vector<int> an;
	};
	std::vector<Query> qrs(nq);
	for(int k=0;k<nq;++k){
		std::cin>>qrs[k].n;
		qrs[k].ind=k;
		qrs[k].an.resize(nn-len+1);
	}
	std::sort(begin(qrs),end(qrs),[](Query const& a,Query const& b){return a.n<b.n;});

	std::vector<int> lb(len+1,-1);
	// lb[d] = min k : d <= qrs[k].n
	for(int k=nq;k--;)
		lb[qrs[k].n]=k;
	for(int d=len;d--;)
		if(lb[d]<0)
			lb[d]=lb[d+1];

	for(int del=1;del<=nn-len;++del){ // difference between two segment position
		int i=0;
		int j=del;
		int d=0;for(int z=0;z<len;++z)d+=a[z]!=a[j+z];
		while(true){
			int lbd=lb[d];
			if(lbd>=0){
				++qrs[lbd].an[i];
				++qrs[lbd].an[j];
			}

			if(j+len==nn)break;
			d-=a[i]!=a[j];
			d+=a[i+len]!=a[j+len];
			++i;++j;
		}
	}

	for(int k=1;k<nq;++k)
		for(int i=0;i<=nn-len;++i)
			qrs[k].an[i]+=qrs[k-1].an[i];

	std::sort(begin(qrs),end(qrs),[](Query const& a,Query const& b){return a.ind<b.ind;}); // may be in O(n)
	for(int k=0;k<nq;++k){
		for(int x:qrs[k].an)
			std::cout<<x<<' ';
		std::cout<<'\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 11 ms 384 KB Output is correct
14 Correct 8 ms 512 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 8 ms 640 KB Output is correct
17 Correct 7 ms 512 KB Output is correct
18 Correct 8 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 196 ms 516 KB Output is correct
2 Correct 125 ms 476 KB Output is correct
3 Correct 114 ms 476 KB Output is correct
4 Correct 111 ms 632 KB Output is correct
5 Correct 48 ms 632 KB Output is correct
6 Correct 106 ms 560 KB Output is correct
7 Correct 73 ms 512 KB Output is correct
8 Correct 120 ms 632 KB Output is correct
9 Correct 117 ms 552 KB Output is correct
10 Correct 115 ms 560 KB Output is correct
11 Correct 8 ms 384 KB Output is correct
12 Correct 66 ms 512 KB Output is correct
13 Correct 60 ms 512 KB Output is correct
14 Correct 58 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 196 ms 516 KB Output is correct
2 Correct 125 ms 476 KB Output is correct
3 Correct 114 ms 476 KB Output is correct
4 Correct 111 ms 632 KB Output is correct
5 Correct 48 ms 632 KB Output is correct
6 Correct 106 ms 560 KB Output is correct
7 Correct 73 ms 512 KB Output is correct
8 Correct 120 ms 632 KB Output is correct
9 Correct 117 ms 552 KB Output is correct
10 Correct 115 ms 560 KB Output is correct
11 Correct 8 ms 384 KB Output is correct
12 Correct 66 ms 512 KB Output is correct
13 Correct 60 ms 512 KB Output is correct
14 Correct 58 ms 512 KB Output is correct
15 Correct 163 ms 480 KB Output is correct
16 Correct 100 ms 604 KB Output is correct
17 Correct 125 ms 560 KB Output is correct
18 Correct 113 ms 608 KB Output is correct
19 Correct 112 ms 568 KB Output is correct
20 Correct 113 ms 512 KB Output is correct
21 Correct 115 ms 560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 11 ms 384 KB Output is correct
14 Correct 8 ms 512 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 8 ms 640 KB Output is correct
17 Correct 7 ms 512 KB Output is correct
18 Correct 8 ms 640 KB Output is correct
19 Correct 196 ms 516 KB Output is correct
20 Correct 125 ms 476 KB Output is correct
21 Correct 114 ms 476 KB Output is correct
22 Correct 111 ms 632 KB Output is correct
23 Correct 48 ms 632 KB Output is correct
24 Correct 106 ms 560 KB Output is correct
25 Correct 73 ms 512 KB Output is correct
26 Correct 120 ms 632 KB Output is correct
27 Correct 117 ms 552 KB Output is correct
28 Correct 115 ms 560 KB Output is correct
29 Correct 8 ms 384 KB Output is correct
30 Correct 66 ms 512 KB Output is correct
31 Correct 60 ms 512 KB Output is correct
32 Correct 58 ms 512 KB Output is correct
33 Correct 163 ms 480 KB Output is correct
34 Correct 100 ms 604 KB Output is correct
35 Correct 125 ms 560 KB Output is correct
36 Correct 113 ms 608 KB Output is correct
37 Correct 112 ms 568 KB Output is correct
38 Correct 113 ms 512 KB Output is correct
39 Correct 115 ms 560 KB Output is correct
40 Correct 225 ms 1912 KB Output is correct
41 Correct 12 ms 640 KB Output is correct
42 Correct 138 ms 1912 KB Output is correct
43 Correct 119 ms 1656 KB Output is correct
44 Correct 118 ms 1912 KB Output is correct
45 Correct 348 ms 8056 KB Output is correct
46 Correct 17 ms 1152 KB Output is correct
47 Correct 280 ms 8312 KB Output is correct
48 Correct 167 ms 6264 KB Output is correct
49 Correct 168 ms 7032 KB Output is correct