QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#184253 | #5979. Log Set | atgc | 25 ✓ | 6ms | 3952kb | C++14 | 1.6kb | 2023-09-20 15:49:31 | 2023-09-20 15:49:31 |
Judging History
answer
/*YYC is Thinking Here*/
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e7+10;
struct node{ int s,p; }a[maxn << 1];
bool cmps(node a,node b) { return a.s < b.s; }
int T,n,bas,ans[64],tp;
void roll(int w) {
for(int i = 1,j = 1;i <= n;++i) {
if(!a[i].p) continue;
while(a[j].s != a[i].s+w) ++j;
a[j].p -= a[i].p;
}
int m = 0;
for(int i = 1;i <= n;++i) if(a[i].p) a[++m] = a[i];
n = m;
}
void push(int w) {
for(int i = 1;i <= n;++i) a[i+n] = {a[i].s+w,a[i].p};
inplace_merge(a+1,a+n+1,a+2*n+1,cmps);
int m = 0;
for(int i = 1,c=0;i <= n+n;++i) {
c += a[i].p;
if(a[i].s != a[i+1].s)
a[++m] = {a[i].s,c}, c = 0;
} n=m;
}
signed main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
ios::sync_with_stdio(0),cin.tie(0);
cin>>T;
for(int _ = 1;_ <= T;++_) {
cin>>n;
for(int i = 1;i <= n;++i) cin>>a[i].s;
for(int i = 1;i <= n;++i) cin>>a[i].p;
bas = -a[1].s;
for(int i = 1;i <= n;++i) a[i].s += bas;
int c0 = __lg(a[1].p);
for(int i = 1;i <= n;++i) a[i].p >>= c0;
tp = 0;
while(n != 1) {
ans[++tp] = a[n].s - a[n-1].s;
roll(ans[tp]);
}
for(int i = 1;i <= tp;++i) push(ans[i]);
sort(ans+1,ans+tp+1,greater<>());
for(int i = 1;bas && i <= tp;++i)
if(lower_bound(a+1,a+n+1,node{bas-ans[i]},cmps)->s == bas-ans[i])
roll(ans[i]), ans[i] = -ans[i], bas += ans[i];
while(c0--) ans[++tp] = 0;
sort(ans+1,ans+tp+1);
cout<<"Case #"<<_<<": ";
for(int i = 1;i <= tp;++i) cout<<ans[i]<<' ';
cout<<'\n';
}
}
/*
* I love it all
* Go forward,move forward !
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 6
Accepted
Test #1:
score: 6
Accepted
time: 4ms
memory: 3896kb
input:
100 36 0 2 4 53591 53592 53593 53594 53595 53596 74164 74166 74168 107182 107183 107184 107185 107186 107187 127755 127756 127757 127758 127759 127760 160774 160776 160778 181346 181347 181348 181349 181350 181351 234938 234940 234942 1 2 1 2 1 4 2 2 1 1 2 1 1 2 2 4 1 2 2 1 4 2 2 1 1 2 1 1 2 2 4 1 2...
output:
Case #1: 2 2 53591 53591 53592 74164 Case #2: 1 15547 76676 76677 153352 Case #3: 1 1 1 1 2 Case #4: 1 1 2 2 Case #5: 9242 9243 77639 86881 96123 96123 201487 Case #6: 0 0 0 1 8 16 Case #7: 22874 72322 95195 95195 95195 95195 190390 Case #8: 1 2 4 Case #9: 0 0 1 1 1 1 12 15 Case #10: 0 0 1 ...
result:
ok 100 lines
Subtask #2:
score: 19
Accepted
Test #2:
score: 19
Accepted
time: 6ms
memory: 3952kb
input:
100 10 -4 -3 -2 -1 0 1 2 3 4 5 1 3 4 4 4 4 4 4 3 1 11 -4 -3 -2 0 1 2 3 4 6 7 8 2 4 2 2 4 4 4 2 2 4 2 11 -3 -2 -1 0 1 2 3 4 5 6 7 2 4 4 8 10 8 10 8 4 4 2 56 -114052 -114051 -114050 -96688 -96687 -96686 -96685 -79323 -79322 -79321 -79320 -65712 -65711 -65710 -65706 -65705 -65704 -61958 -61957 -61956 -...
output:
Case #1: -4 1 1 1 2 Case #2: -4 0 1 1 6 Case #3: -3 0 1 1 2 3 Case #4: -48346 -48340 -17365 -1 1 17364 17365 Case #5: -65620 -65619 -42396 1 23223 65619 65619 Case #6: -80 -79 -79 -78 -78 -75 -74 -73 -71 -68 -66 -66 -66 -65 -62 -61 -61 -60 -60 -7 -5 1 3 5 6 10 10 19 20 23 24 26 26 30 30 31 32 3...
result:
ok 100 lines
Extra Test:
score: 0
Extra Test Passed