답안 #897624

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
897624 2024-01-03T13:45:55 Z 8pete8 Lottery (CEOI18_lot) C++17
100 / 100
524 ms 8840 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<float.h>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
using namespace std;
//#define int long long
#define double long double
const int mod=998244353,mxn=1e4,lg=22;//inf=1e18,minf=-1e18,Mxn=100000;
int n,k,q;
int v[mxn+10],ans[105][mxn+1],qpos[mxn+10];
bitset<mxn+10>qry;
vector<int>mp[mxn+10];
map<int,int>pos;
int c=0;
bool cmp(pii a,pii b){return a.s<b.s;}
int32_t main(){
    fastio
	cin>>n>>k;
	vector<int>com;
	for(int i=0;i<n;i++)cin>>v[i],com.pb(v[i]);
	sort(all(com));
	unique(all(com));
	for(auto i:com)pos[i]=++c;
	for(int i=0;i<n;i++)v[i]=pos[v[i]];
	int cur=0;
	cin>>q;
	vector<pii>qry(q);
	for(int i=0;i<q;i++){
		cin>>qry[i].f,qry[i].s=i;
		qry[i].f=k-qry[i].f;
	}
	sort(all(qry));
	fill(qpos,qpos+n,-1);
	for(int i=0;i<=n;i++){
		while(cur<qry.size()&&qry[cur].f<=i)cur++;
		qpos[i]=cur-1;
	}
	vector<int>cnt(2*n+1,0);
	for(int i=0;i<n;i++)mp[v[i]].pb(i);
	for(int i=0;i<k;i++)for(auto j:mp[v[i]])cnt[j-i+n]++;
	for(int i=n+1;i<2*n-k+1;i++)if(qpos[cnt[i]]!=-1)ans[qpos[cnt[i]]][0]++;
	int l=0,r=k-1;
	while(r<n-1){
		for(auto j:mp[v[l]])cnt[j+n]--;
		l++;
		for(int j=2*n;j>=1;j--)cnt[j]=cnt[j-1];
		r++;
		for(auto j:mp[v[r]])cnt[j-(k-1)+n]++;
		for(int i=n;i<2*n-k+1;i++)if(i-n!=l&&qpos[cnt[i]]!=-1)ans[qpos[cnt[i]]][l]++;
	}
	for(int i=q;i>=0;i--)for(int j=0;j<n;j++)ans[i][j]+=ans[i+1][j];
	sort(all(qry),cmp);
	for(auto i:qry){
		for(int j=0;j<n-k+1;j++)cout<<ans[qpos[i.f]][j]<<" ";
		cout<<'\n';
	}
	return 0;
}

Compilation message

lot.cpp: In function 'int32_t main()':
lot.cpp:64:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |   while(cur<qry.size()&&qry[cur].f<=i)cur++;
      |         ~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 10 ms 2652 KB Output is correct
14 Correct 7 ms 2908 KB Output is correct
15 Correct 3 ms 2652 KB Output is correct
16 Correct 6 ms 2652 KB Output is correct
17 Correct 5 ms 2816 KB Output is correct
18 Correct 5 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 253 ms 2932 KB Output is correct
2 Correct 174 ms 2944 KB Output is correct
3 Correct 105 ms 2940 KB Output is correct
4 Correct 80 ms 3020 KB Output is correct
5 Correct 93 ms 3024 KB Output is correct
6 Correct 72 ms 3032 KB Output is correct
7 Correct 177 ms 3056 KB Output is correct
8 Correct 261 ms 3060 KB Output is correct
9 Correct 88 ms 2912 KB Output is correct
10 Correct 87 ms 2908 KB Output is correct
11 Correct 8 ms 2652 KB Output is correct
12 Correct 61 ms 3228 KB Output is correct
13 Correct 54 ms 3104 KB Output is correct
14 Correct 70 ms 3156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 253 ms 2932 KB Output is correct
2 Correct 174 ms 2944 KB Output is correct
3 Correct 105 ms 2940 KB Output is correct
4 Correct 80 ms 3020 KB Output is correct
5 Correct 93 ms 3024 KB Output is correct
6 Correct 72 ms 3032 KB Output is correct
7 Correct 177 ms 3056 KB Output is correct
8 Correct 261 ms 3060 KB Output is correct
9 Correct 88 ms 2912 KB Output is correct
10 Correct 87 ms 2908 KB Output is correct
11 Correct 8 ms 2652 KB Output is correct
12 Correct 61 ms 3228 KB Output is correct
13 Correct 54 ms 3104 KB Output is correct
14 Correct 70 ms 3156 KB Output is correct
15 Correct 524 ms 2908 KB Output is correct
16 Correct 77 ms 2988 KB Output is correct
17 Correct 106 ms 3088 KB Output is correct
18 Correct 80 ms 3116 KB Output is correct
19 Correct 78 ms 2904 KB Output is correct
20 Correct 90 ms 3072 KB Output is correct
21 Correct 83 ms 3072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 10 ms 2652 KB Output is correct
14 Correct 7 ms 2908 KB Output is correct
15 Correct 3 ms 2652 KB Output is correct
16 Correct 6 ms 2652 KB Output is correct
17 Correct 5 ms 2816 KB Output is correct
18 Correct 5 ms 2652 KB Output is correct
19 Correct 253 ms 2932 KB Output is correct
20 Correct 174 ms 2944 KB Output is correct
21 Correct 105 ms 2940 KB Output is correct
22 Correct 80 ms 3020 KB Output is correct
23 Correct 93 ms 3024 KB Output is correct
24 Correct 72 ms 3032 KB Output is correct
25 Correct 177 ms 3056 KB Output is correct
26 Correct 261 ms 3060 KB Output is correct
27 Correct 88 ms 2912 KB Output is correct
28 Correct 87 ms 2908 KB Output is correct
29 Correct 8 ms 2652 KB Output is correct
30 Correct 61 ms 3228 KB Output is correct
31 Correct 54 ms 3104 KB Output is correct
32 Correct 70 ms 3156 KB Output is correct
33 Correct 524 ms 2908 KB Output is correct
34 Correct 77 ms 2988 KB Output is correct
35 Correct 106 ms 3088 KB Output is correct
36 Correct 80 ms 3116 KB Output is correct
37 Correct 78 ms 2904 KB Output is correct
38 Correct 90 ms 3072 KB Output is correct
39 Correct 83 ms 3072 KB Output is correct
40 Correct 216 ms 3668 KB Output is correct
41 Correct 18 ms 2908 KB Output is correct
42 Correct 110 ms 3664 KB Output is correct
43 Correct 84 ms 3356 KB Output is correct
44 Correct 83 ms 3412 KB Output is correct
45 Correct 251 ms 8664 KB Output is correct
46 Correct 22 ms 5200 KB Output is correct
47 Correct 282 ms 8840 KB Output is correct
48 Correct 119 ms 7208 KB Output is correct
49 Correct 121 ms 7764 KB Output is correct