QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#844711 | #92. Santa Claus | H_Z_J | 0 | 126ms | 11616kb | C++20 | 3.1kb | 2025-01-06 10:20:12 | 2025-01-06 10:20:13 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define rep(i, j, k) for(int i=j;i<=k;++i)
#define rep1(i, j, k) for(int i=k;i>=j;--i)
#define pii pair<int, int>
#define pb push_back
#define ft first
#define sd second
using namespace std;
const int N=1e5+5, inf=2e9;
int n, t, a[N], b[N], c[N], pla[N];
pii d[N];
vector<int> v[N];
int mi[N<<2], fro[N<<2];
int tag[N<<2];
#define lz id<<1
#define rz id<<1|1
#define mid ((l+r)>>1)
void pushup(int id){
if(mi[lz]<=mi[rz]) mi[id]=mi[lz], fro[id]=fro[lz];
else mi[id]=mi[rz], fro[id]=fro[rz];
}
void build(int id, int l, int r){
mi[id]=inf, tag[id]=0;
if(l==r) return mi[id]=-l, void();
build(lz, l, mid), build(rz, mid+1, r);
pushup(id);
}
void build1(int id, int l, int r){
mi[id]=inf;
if(l==r) return mi[id]=pla[l], fro[id]=l, void();
build1(lz, l, mid), build1(rz, mid+1, r);
pushup(id);
}
void upd(int id, int l, int r, int p){
if(l>=p) return ++mi[id], ++tag[id], void();
if(tag[id]){
tag[lz]+=tag[id], tag[rz]+=tag[id];
mi[lz]+=tag[id], mi[rz]+=tag[id];
tag[id]=0;
}
if(p<=mid) upd(lz, l, mid, p);
upd(rz, mid+1, r, p);
pushup(id);
}
void upd1(int id, int l, int r, int p){
if(l==r) return mi[id]=inf, void();
if(p<=mid) upd1(lz, l, mid, p);
else upd1(rz, mid+1, r, p);
pushup(id);
}
pii qry1(int id, int l, int r, int p){
if(l>=p) return {mi[id], fro[id]};
pii x=qry1(rz, mid+1, r, p);
if(p<=mid) x=min(x, qry1(lz, l, mid, p));
return x;
}
int ans[N];
set<int> s;
multiset<pii> ss;
signed main(){
scanf("%d", &t);
while(t--){
scanf("%d", &n);
rep(i, 1, n) scanf("%d", a+i);
rep(i, 1, n) scanf("%d", b+i);
rep(i, 1, n) scanf("%d", c+i);
s.clear(), ss.clear();
rep(i, 1, n) v[i].clear();
int cnt=0;
rep(i, 1, n) if(!b[i]) ++cnt;
build(1, 1, cnt);
if(!t) cout<<n<<" "<<cnt<<" ";
int x=0, sum=0;
rep(i, 1, n){
if(!b[i]){
d[++sum]={c[i], i};
if(sum==cnt){
sort(d+1, d+cnt+1);
rep(j, 1, i){
if(!b[j]) continue;
pii fd={c[j], 0};
int p=lower_bound(d+1, d+cnt+1, fd)-d;
if(p<=cnt) upd(1, 1, cnt, p), v[p].pb(j);
}
}
}else if(sum==cnt){
pii fd={c[i], 0};
int p=lower_bound(d+1, d+cnt+1, fd)-d;
if(p<=cnt) upd(1, 1, cnt, p), v[p].pb(i);
}
if(mi[1]==0){
x=i;
break;
}
ans[i]=-1;
}
if(!t) cout<<x<<endl;
if(!x){
rep(i, 1, cnt) printf("%d ", ans[i]);
continue;
}
rep(i, 1, cnt){
for(int it : v[i]) s.insert(it);
auto it=s.upper_bound(d[i].sd);
if(it==s.end()) --it, pla[i]=*it;
else pla[i]=inf;
s.erase(it);
}
build1(1, 1, cnt);
if(mi[1]^inf) ans[x]=2*a[x]-a[mi[1]];
else ans[x]=a[x];
rep(i, x+1, n){
pii fd={c[i], 0};
int p=lower_bound(d+1, d+cnt+1, fd)-d;
if(p<=cnt){
pii x=qry1(1, 1, cnt, p);
upd1(1, 1, cnt, x.sd);
}
if(mi[1]^inf) ans[i]=2*a[i]-a[mi[1]];
else ans[i]=a[i];
}
rep(i, 1, n) printf("%d ", ans[i]);
puts("");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 10124kb
input:
5 84 25 26 31 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 90 94 102 105 112 117 125 134 140 146 147 156 157 167 173 183 186 187 190 198 206 212 220 224 226 234 235 240 250 251 259 261 268 271 1 0 0 0 0 0...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 349 190 198 206 212 220 224 226 234 235 240 250 251 259 261 268 271 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer 5th lines differ - expected: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...149 154 157 161 162 170 173 175', found: '67 17 0'
Test #2:
score: 0
Wrong Answer
time: 2ms
memory: 8088kb
input:
10 134 105 106 107 108 109 110 111 112 113 114 115 116 117 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 1...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer 1st lines differ - expected: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...323 330 338 345 352 361 365 369', found: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...59 461 469 475 484 489 494 502 '
Test #3:
score: 0
Wrong Answer
time: 4ms
memory: 7960kb
input:
10 1379 85 86 151 152 155 156 157 158 159 160 161 162 163 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 23...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer 1st lines differ - expected: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...7 3206 3209 3216 3223 3232 3241', found: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ... 3206 3209 3216 3223 3232 3241 '
Test #4:
score: 0
Wrong Answer
time: 4ms
memory: 8116kb
input:
10 2709 75 76 81 88 89 119 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 2...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer 1st lines differ - expected: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...0 5978 5980 5985 5991 5995 6000', found: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ... 6479 6484 6485 6488 6493 6502 '
Test #5:
score: 0
Wrong Answer
time: 17ms
memory: 8368kb
input:
10 5562 75 76 81 88 89 119 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 2...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer 1st lines differ - expected: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...3 12703 12706 12707 12714 12719', found: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ... 12703 12706 12707 12714 12719 '
Test #6:
score: 0
Wrong Answer
time: 27ms
memory: 8696kb
input:
10 13123 75 76 81 88 89 119 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 ...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer 1st lines differ - expected: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...6 27095 27101 27108 27112 27119', found: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ... 33629 33633 33638 33645 33651 '
Test #7:
score: 0
Wrong Answer
time: 52ms
memory: 7216kb
input:
10 27599 75 76 81 88 89 119 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 ...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer 1st lines differ - expected: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...5 62161 62170 62177 62181 62183', found: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ... 62161 62170 62177 62181 62183 '
Test #8:
score: 0
Wrong Answer
time: 70ms
memory: 11616kb
input:
10 41646 75 76 81 88 89 119 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 ...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer 1st lines differ - expected: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...0 94273 94282 94292 94295 94299', found: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ... 94273 94282 94292 94295 94299 '
Test #9:
score: 0
Wrong Answer
time: 81ms
memory: 9380kb
input:
10 95045 75 76 81 88 89 119 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 ...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer 1st lines differ - expected: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...605 207608 207618 207627 207632', found: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ... 71259 71262 71271 71279 71285 '
Test #10:
score: 0
Wrong Answer
time: 126ms
memory: 9668kb
input:
10 96068 75 76 81 88 89 119 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 ...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer 1st lines differ - expected: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...155 213161 213171 213174 213183', found: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...00 156209 156219 156224 156227 '