QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#68991 | #4583. Concerto de Pandemic | socpite | WA | 844ms | 41428kb | C++20 | 2.6kb | 2022-12-22 11:38:15 | 2022-12-22 11:38:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
const int maxn = 2e5+5;
const ll inf = 1e18+5;
ll n, m, k, p, sz;
ll pfx[maxn], C[maxn], D[maxn], mm[maxn];
ll query(int l, int r){
if(r < l)return pfx[r]+pfx[n]-pfx[l-1] + (n-l+r);
else return pfx[r]-pfx[l-1] + (r-l);
}
ll dist(int a, int x, int id){
return id ? query(a, x) : query(x, a);
}
int nxt(int x){
return x == sz-1 ? 0 : x+1;
}
int prv(int x){
return x == 0 ? sz-1 : x-1;
}
ll st[20][maxn];
ll chk(ll x){
vector<int> epos;
for(int i = 1; i <= n; i++)if(pfx[i] == pfx[i-1]){
epos.push_back(i);
//cout << i << " ";
}
sz = epos.size();
//cout << "\n";
int ptr = 0, ptr2 = 0, cnt = 0;
for(int i = 0; i < epos.size(); i++){
while(query(epos[i], epos[ptr]) <= x){
if(ptr == ptr2){
if(mm[epos[ptr2]])cnt++;
if(cnt == k)return 1;
ptr2 = nxt(ptr2);
}
ptr = nxt(ptr);
}
//cout << cnt << "\n";
while(query(epos[ptr-1], epos[ptr2]) <= x){
if(mm[epos[ptr2]])cnt++;
if(cnt == k)return 1;
ptr2 = nxt(ptr2);
}
if(mm[epos[i]]){
//cout << x << " " << epos[i] << " " << epos[ptr] << " " << epos[ptr2] << " " << cnt << "\n";
st[0][mm[epos[i]]-1] = cnt;
assert(cnt);
cnt--;
}
}
//for(int i = 0; i < k; i++)st[0][i] = 0;
for(int i = 1; i < 20; i++){
for(int j = 0; j < k; j++){
int nxt = (j+st[i-1][j])%k;
st[i][j]=st[i-1][j]+st[i-1][nxt];
}
}
int ans = p+1;
for(int i = 0; i < k; i++){
int tot = 0, crr = 0;
for(int j = 19; j >= 0; j--){
if(st[j][(i+crr)%k]+crr < k){
crr+=st[j][(i+crr)%k];
tot+=(1<<j);
}
}
ans = min(ans, tot);
}
return ans+1;
}
int main(){
cin >> n >> m >> k >> p;
for(int i = 1; i <= m; i++)cin >> C[i] >> pfx[C[i]];
for(int i = 1; i <= n; i++)pfx[i]+=pfx[i-1];
if(k == 1){
cout << 0;
return 0;
}
for(int i = 0; i < k; i++){
cin >> D[i];
}
sort(D, D+k);
for(int i = 0; i < k; i++)mm[D[i]]=i+1;
ll l = 0, r = inf;
while(l < r){
ll mid = (l+r)>>1;
if(chk(mid) <= p)r=mid;
else l = mid+1;
}
//cout << query(5, 2) << "\n";
cout << l << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 38232kb
input:
10 4 3 2 1 2 4 4 6 2 7 5 2 5 8
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 1ms
memory: 40144kb
input:
8 1 3 5 1 5 4 2 7
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 4ms
memory: 38272kb
input:
5 2 2 1 1 14 2 14 3 5
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 3ms
memory: 5568kb
input:
2 1 1 1 1 200000 2
output:
0
result:
ok single line: '0'
Test #5:
score: -100
Wrong Answer
time: 844ms
memory: 41428kb
input:
190976 113222 55610 23475 51263 120558 10007 171596 46671 108981 117183 169457 18187 84735 149298 124718 79376 129184 28117 76880 109791 87521 114840 59510 38014 178362 41701 11344 27561 192741 173835 54534 71368 76692 122745 95537 152595 158352 43901 162441 98927 105784 22484 96000 19443 113614 370...
output:
170526
result:
wrong answer 1st lines differ - expected: '170531', found: '170526'