ログインしてください。
提出 #49504325
ソースコード 拡げる
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
# define int long long
# define For(i, n) for(int i=0; i<n; i++)
# define Fori(i, n) for(int i=1; i<=n; i++)
# define Each(x, v) for(auto x : v)
const int maxn = 4e5;
int tor[maxn+5];
int n, m, k;
int arr[maxn+5];
int window = 0;
int curcnt[maxn+5], cnt[maxn+5];
int bit[maxn+5];
int ls(int x) { return x & (-x); }
void upd(int x, int val){
for(int i=x; i<=maxn; i+=ls(i)) bit[i] += val;
}
int get(int x){
int res = 0;
for(int i=x; i>0; i-=ls(i)) res += bit[i];
return res;
}
int get(int l, int r){
return get(r) - get(l-1);
}
bool ok(int l, int r){
if(r >= l+n) return false;
if(curcnt[arr[r]] > 0) return true;
if(curcnt[arr[r]] == 0 && window < m) return true;
return false;
}
queue<int> pos[maxn+5];
set<int> nums;
signed main(){
ios_base :: sync_with_stdio(false);
cin >> n >> m >> k;
for(int i=1; i<=n; i++){
cin >> arr[i];
pos[arr[i]].push(i);
nums.insert(arr[i]);
cnt[arr[i]]++;
}
for(int i=n+1; i<=2*n; i++){
arr[i] = arr[i-n];
pos[arr[i]].push(i);
}
int r = 0;
for(int l=1; l<=n; l++){
while(ok(l, r+1)) {
r++;
curcnt[arr[r]]++;
if(curcnt[arr[r]] == 1) window++;
}
tor[l] = r;
curcnt[arr[l]]--;
if(curcnt[arr[l]] == 0) window--;
}
for(int x: nums){
int p = pos[x].front();
upd(p, min(cnt[x], k));
}
for(int i=1; i<=n; i++){
int l = i, r = tor[i];
cout << get(l, r) << "\n";
int p = pos[arr[i]].front();
upd(p, -min(cnt[arr[i]], k));
pos[arr[i]].pop();
if (!pos[arr[i]].empty()){
p = pos[arr[i]].front();
upd(p, min(cnt[arr[i]], k));
}
}
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | F - Usual Color Ball Problems |
| ユーザ | fonmagnus |
| 言語 | C++ 20 (gcc 12.2) |
| 得点 | 0 |
| コード長 | 1773 Byte |
| 結果 | WA |
| 実行時間 | 308 ms |
| メモリ | 292736 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 0 / 550 | ||||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | example0.txt, example1.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, example0.txt, example1.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 000.txt | AC | 124 ms | 272408 KiB |
| 001.txt | AC | 168 ms | 281444 KiB |
| 002.txt | WA | 173 ms | 281660 KiB |
| 003.txt | AC | 170 ms | 281528 KiB |
| 004.txt | AC | 170 ms | 281548 KiB |
| 005.txt | AC | 260 ms | 287248 KiB |
| 006.txt | AC | 249 ms | 289176 KiB |
| 007.txt | AC | 181 ms | 280488 KiB |
| 008.txt | AC | 130 ms | 273280 KiB |
| 009.txt | AC | 178 ms | 279976 KiB |
| 010.txt | AC | 186 ms | 281140 KiB |
| 011.txt | AC | 132 ms | 273808 KiB |
| 012.txt | AC | 192 ms | 281320 KiB |
| 013.txt | AC | 214 ms | 284152 KiB |
| 014.txt | AC | 232 ms | 285524 KiB |
| 015.txt | AC | 236 ms | 286324 KiB |
| 016.txt | AC | 135 ms | 273972 KiB |
| 017.txt | WA | 167 ms | 281568 KiB |
| 018.txt | WA | 166 ms | 281576 KiB |
| 019.txt | WA | 164 ms | 281560 KiB |
| 020.txt | WA | 169 ms | 281492 KiB |
| 021.txt | WA | 165 ms | 281556 KiB |
| 022.txt | AC | 218 ms | 282520 KiB |
| 023.txt | AC | 203 ms | 284348 KiB |
| 024.txt | AC | 217 ms | 282600 KiB |
| 025.txt | AC | 195 ms | 284752 KiB |
| 026.txt | AC | 217 ms | 282784 KiB |
| 027.txt | AC | 229 ms | 285552 KiB |
| 028.txt | AC | 233 ms | 285668 KiB |
| 029.txt | AC | 298 ms | 291732 KiB |
| 030.txt | AC | 286 ms | 290496 KiB |
| 031.txt | AC | 261 ms | 287376 KiB |
| 032.txt | AC | 301 ms | 292736 KiB |
| 033.txt | AC | 308 ms | 292612 KiB |
| 034.txt | AC | 297 ms | 292604 KiB |
| 035.txt | AC | 303 ms | 292620 KiB |
| 036.txt | AC | 298 ms | 292608 KiB |
| 037.txt | AC | 168 ms | 281540 KiB |
| 038.txt | AC | 166 ms | 281536 KiB |
| 039.txt | WA | 171 ms | 281516 KiB |
| 040.txt | AC | 230 ms | 281544 KiB |
| 041.txt | AC | 192 ms | 284396 KiB |
| 042.txt | AC | 194 ms | 284508 KiB |
| 043.txt | WA | 194 ms | 284428 KiB |
| 044.txt | AC | 195 ms | 284496 KiB |
| 045.txt | AC | 297 ms | 292480 KiB |
| 046.txt | AC | 299 ms | 292616 KiB |
| 047.txt | AC | 298 ms | 292572 KiB |
| 048.txt | AC | 303 ms | 292620 KiB |
| example0.txt | AC | 125 ms | 272344 KiB |
| example1.txt | AC | 125 ms | 272320 KiB |