답안 #253358

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
253358 2020-07-27T18:52:59 Z cfalas Lottery (CEOI18_lot) C++14
100 / 100
947 ms 12408 KB
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID (l+r)/2
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;
 
#define EPS 1e-6
 
#define T double
int main(){
    int n, l;
    cin>>n>>l;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
	//for(int i=0;i<n;i++) cout<<a[i]<<" ";
	//cout<<endl;
	//for(int i=0;i<n;i++) cout<<a[i]<<" ";
	//cout<<endl;
 
    int q;
    cin>>q;
	vii qs;
	set<int> qus;
	map<int, vector<int> > same;
	for(int i=0;i<q;i++){
        int z;
        cin>>z;
		if(qus.count(z)==0)
			qs.push_back(ii(z, i));
		else same[z].push_back(i);
		qus.insert(z);
    }
	//cout<<l<<endl;
	qs.push_back(ii(l, q));
	sort(qs.begin(), qs.end());
	int ans[q+2][n] = {};
	//for(auto v : qs) cout<<v.F<<" "<<v.S<<endl;
	//cout<<endl;

	for(int i=1;i<n-l+1;i++){
		//cout<<"off "<<i<<endl;
		//cout<<endl;
		int dist=0;
		for(int j=0;j<l;j++){
			assert(i+j<n);
			if(a[j]!=a[i+j]) dist++;
		}
		int pos=-1;
		for(unsigned j=0;j<qs.size();j++){
			//cout<<dist<<"\n";
			assert(j<qs.size());
			if(dist<=qs[j].F) { pos = j; break;}
		}
		//cout<<endl;
		//cout<<dist<<" "<<pos<<endl;
		assert(pos!=-1);
		ans[pos][0]++, ans[pos][i]++;
		//cout<<a<<" "<<ans<<endl;
		for(int j=l;j+i<n;j++){
			//cout<<endl;
			//for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
			//cout<<"current(" <<a[j-2]<<" "<<a[j-1]<<") vs ("<<a[i+j-2]<<" "<<a[i+j-1]<<")\n";
			//cout<<"dist "<<dist<<endl;
			//cout<<"remove "<<a[j-l]<<" "<<a[i+j-l]<<endl;
			//cout<<"add "<<a[j]<<" "<<a[i+j]<<endl;
			//cout<<endl;
			if(a[j-l]!=a[i+j-l]) dist--;
			if(a[j]!=a[i+j]) dist++;
			//cout<<"new dist "<<dist<<endl;
			assert(pos>=0 && pos<(int)qs.size());
			//cout<<"old pos "<<pos<<endl;
			if(dist<=qs[pos].F){
				if(pos>0 && dist<=qs[pos-1].F) pos--;
				ans[pos][j-l+1]++, ans[pos][i+j-l+1]++;
			}
			else if(pos<q && dist<=qs[pos+1].F){
				pos++;
				ans[pos][j-l+1]++, ans[pos][i+j-l+1]++;
			}
			//cout<<"new pos "<<pos<<endl;
			assert(pos>=0 && pos<(int)qs.size());
		}
		//cout<<"-----\n";
	}
	int fin[q+2][n];
	for(int i=0;i<n;i++){
		fin[qs[0].S][i] = ans[0][i];
	}
	for(int t=1;t<qs.size();t++){
		for(int i=0;i<n-l+1;i++){
			fin[qs[t].S][i] = ans[t][i] + fin[qs[t-1].S][i];
			//cout<<qs[t].F<<" "<<qs[t].S<<endl;
			assert(qs[t].S<=q+1);
			//if(qs[t].S==7) cout<<"what\n";
			//if(qs[t].F==2) cout<<ans[t][i]<<" "<<fin[qs[t-1].S][i]<<endl;
			for(auto s_ind : same[qs[t].F]){
				fin[s_ind][i] = ans[t][i] + fin[qs[t-1].S][i];
				assert(s_ind<q);
			}
		}
	}
	for(int t=0;t<q;t++){
		for(int i=0;i<n-l+1;i++) cout<<fin[t][i]<<" ";
		cout<<endl;
	}
}

Compilation message

lot.cpp: In function 'int main()':
lot.cpp:102:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int t=1;t<qs.size();t++){
              ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 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 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 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 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 16 ms 512 KB Output is correct
14 Correct 15 ms 768 KB Output is correct
15 Correct 9 ms 640 KB Output is correct
16 Correct 15 ms 768 KB Output is correct
17 Correct 18 ms 768 KB Output is correct
18 Correct 15 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 563 ms 632 KB Output is correct
2 Correct 730 ms 760 KB Output is correct
3 Correct 344 ms 632 KB Output is correct
4 Correct 287 ms 760 KB Output is correct
5 Correct 98 ms 632 KB Output is correct
6 Correct 265 ms 632 KB Output is correct
7 Correct 104 ms 612 KB Output is correct
8 Correct 175 ms 632 KB Output is correct
9 Correct 283 ms 760 KB Output is correct
10 Correct 290 ms 632 KB Output is correct
11 Correct 20 ms 384 KB Output is correct
12 Correct 170 ms 632 KB Output is correct
13 Correct 132 ms 632 KB Output is correct
14 Correct 143 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 563 ms 632 KB Output is correct
2 Correct 730 ms 760 KB Output is correct
3 Correct 344 ms 632 KB Output is correct
4 Correct 287 ms 760 KB Output is correct
5 Correct 98 ms 632 KB Output is correct
6 Correct 265 ms 632 KB Output is correct
7 Correct 104 ms 612 KB Output is correct
8 Correct 175 ms 632 KB Output is correct
9 Correct 283 ms 760 KB Output is correct
10 Correct 290 ms 632 KB Output is correct
11 Correct 20 ms 384 KB Output is correct
12 Correct 170 ms 632 KB Output is correct
13 Correct 132 ms 632 KB Output is correct
14 Correct 143 ms 632 KB Output is correct
15 Correct 368 ms 760 KB Output is correct
16 Correct 250 ms 632 KB Output is correct
17 Correct 317 ms 632 KB Output is correct
18 Correct 299 ms 620 KB Output is correct
19 Correct 307 ms 616 KB Output is correct
20 Correct 294 ms 636 KB Output is correct
21 Correct 294 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 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 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 16 ms 512 KB Output is correct
14 Correct 15 ms 768 KB Output is correct
15 Correct 9 ms 640 KB Output is correct
16 Correct 15 ms 768 KB Output is correct
17 Correct 18 ms 768 KB Output is correct
18 Correct 15 ms 768 KB Output is correct
19 Correct 563 ms 632 KB Output is correct
20 Correct 730 ms 760 KB Output is correct
21 Correct 344 ms 632 KB Output is correct
22 Correct 287 ms 760 KB Output is correct
23 Correct 98 ms 632 KB Output is correct
24 Correct 265 ms 632 KB Output is correct
25 Correct 104 ms 612 KB Output is correct
26 Correct 175 ms 632 KB Output is correct
27 Correct 283 ms 760 KB Output is correct
28 Correct 290 ms 632 KB Output is correct
29 Correct 20 ms 384 KB Output is correct
30 Correct 170 ms 632 KB Output is correct
31 Correct 132 ms 632 KB Output is correct
32 Correct 143 ms 632 KB Output is correct
33 Correct 368 ms 760 KB Output is correct
34 Correct 250 ms 632 KB Output is correct
35 Correct 317 ms 632 KB Output is correct
36 Correct 299 ms 620 KB Output is correct
37 Correct 307 ms 616 KB Output is correct
38 Correct 294 ms 636 KB Output is correct
39 Correct 294 ms 632 KB Output is correct
40 Correct 847 ms 2940 KB Output is correct
41 Correct 18 ms 1536 KB Output is correct
42 Correct 319 ms 2824 KB Output is correct
43 Correct 299 ms 2552 KB Output is correct
44 Correct 299 ms 2680 KB Output is correct
45 Correct 947 ms 12224 KB Output is correct
46 Correct 28 ms 5632 KB Output is correct
47 Correct 403 ms 12408 KB Output is correct
48 Correct 374 ms 10616 KB Output is correct
49 Correct 377 ms 11256 KB Output is correct