QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#303786 | #7969. 套娃 | Zeardoe | AC ✓ | 75ms | 32528kb | C++20 | 5.1kb | 2024-01-12 23:49:22 | 2024-01-12 23:49:22 |
Judging History
answer
/*
[templates]:
duipai
compre
addhis
floor_sum
matrix
network_flow
polynomial
lca
bitset
valuesgt
fenwick
erbitree
segment
mcmf
primal_dual
centroid
add0cnt
euler
basis
*/
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
#include<bits/stdc++.h>
using namespace std;
#define int long long
//use ll instead of int.
#define f(i, a, b) for(int i = (a); i <= (b); i++)
#define cl(i, n) i.clear(),i.resize(n);
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e18;
//#define cerr if(false)cerr
//#define freopen if(false)freopen
mt19937 rng(std::chrono::high_resolution_clock::now().time_since_epoch().count());
int rnd(int l, int r) {return rng() % (r-l+1) + l; }
#define watch(x) cerr << (#x) << ' '<<'i'<<'s'<<' ' << x << endl
void pofe(int number, int bitnum) {
string s; f(i, 0, bitnum) {s += char(number & 1) + '0'; number >>= 1; }
reverse(s.begin(), s.end()); cerr << s << endl;
return;
}
double runtime() {return 1.0*clock()/CLOCKS_PER_SEC;}
template <typename TYP> void cmax(TYP &x, TYP y) {if(x < y) x = y;}
template <typename TYP> void cmin(TYP &x, TYP y) {if(x > y) x = y;}
//调不出来给我对拍!
//use std::array.
const int N=1e5;
int a[N+10]; int nxt[N+10],cur[N+10];
int sgt[4*N+10];
void add(int now,int l,int r,int x,int k) {
if(l==r) {sgt[now] += k;return; }
int mid=(l+r)>>1; if(x<=mid) add(now*2,l,mid,x,k);
else add(now*2+1,mid+1,r,x,k);
sgt[now]=min(sgt[now*2],sgt[now*2+1]);
}
int erfen(int now,int l,int r) {
if(l==r) {return l;}
int mid=(l+r)>>1;
if(sgt[now*2]>0)return erfen(now*2+1,mid+1,r);
else return erfen(now*2,l,mid);
}
struct qj {
int l,r; int val,t;
bool operator< (const qj op) const {
if(val!=op.val)return val<op.val;
else if(l!=op.l) return l < op.l; else return r<op.r;
}
};
struct rect {
int t,u; int l,r; int val;
}; vector<rect> rec; //这个可以卡常不显式存.
set<qj> kdl;
void eli(int b) {
vector<qj> er,in;
for(auto it:kdl) {
if(it.l<b) {
if(it.r<b) {
rec.push_back({it.l,it.r,it.t,b-1,it.val});
er.push_back(it);
}
else {
rec.push_back({it.l,b-1,it.t,b-1,it.val});
er.push_back(it);
in.push_back({b,it.r,it.val,it.t});
break;
}
}
else break;
}
for(auto it:er) kdl.erase(it);
for(auto it:in) kdl.insert(it);
}
void emin(int b, int u, int q) {
if(b>u)return;
vector<qj> er,in;int tp=inf;
auto fr=kdl.lower_bound({0,0,q+1,0});
for(auto jt=fr;jt!=kdl.end();jt++) {
auto it=*jt;
if(it.l > u) {
break;
}
else {
if(it.val > q) {
cmin(tp,it.l);
er.push_back(it);
if(it.r > u) {
rec.push_back({it.l,u,it.t,b-1,it.val});
in.push_back({u+1,it.r,it.val,it.t});
break;
}
else {
rec.push_back({it.l,it.r,it.t,b-1,it.val});
}
}
}
}
for(auto it:er) kdl.erase(it);
for(auto it:in) kdl.insert(it);
if(tp<=u)kdl.insert({tp,u,q,b});
}
vector<int> in[N+10], out[N+10];
void print() {
cerr<<"Print\n";
for(auto it:kdl) {
cerr<<"["<<it.l<<", "<<it.r<<"], val="<<it.val<<", time="<<it.t<<endl;
}
cerr<<"------------------------\n";
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
// freopen("P9970.in","r",stdin);
// freopen("P9970.out","w",stdout);
// freopen("P9970.ear","w",stderr);
//time_t start = clock();
//think twice,code once.
//think once,debug forever.
int n; cin >> n;
f(i,1,n) cin >> a[i];
f(i,0,n) cur[i]=n+1;
for(int i=n;i>=1;i--) {nxt[i]=cur[a[i]]; cur[a[i]]=i; }
f(i,1,n) {
add(1,0,n,a[i],1); kdl.insert({i,i,erfen(1,0,n),1});
}
// cerr<<runtime()<<endl;
// print();
for(int l=2;l<=n+1;l++) {
int u=a[l-1];
//[l, nxt[u]-1] cmin u.
//less than l quit.
eli(l);
// print();
emin(l, nxt[l-1]-1, u);
// print();
}
// cerr<<runtime()<<endl;
for(auto it:rec) {
// cerr<<"rect: "<<it.l<<" "<<it.r<<" "<<it.t<<" "<<it.u<<", val="<<it.val<<endl;
// cerr<<"range: "<<it.t-it.r+1<<" ~ "<<it.u-it.l+1<<endl;
out[it.u-it.l+1+1].push_back(it.val);
in[it.t-it.r+1].push_back(it.val);
}
f(i,1,4*n+4) sgt[i]=0;
f(i,1,n) {
for(int j:in[i]) {
add(1,0,n,j,1);
}
for(int j:out[i]) {
add(1,0,n,j,-1);
}
cout<<erfen(1,0,n)<<" ";
}
cout<<endl;
//time_t finish = clock();
//cout << "time used:" << (finish-start) * 1.0 / CLOCKS_PER_SEC <<"s"<< endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 10524kb
input:
6 0 0 0 1 2 3
output:
2 3 4 0 0 0
result:
ok single line: '2 3 4 0 0 0 '
Test #2:
score: 0
Accepted
time: 2ms
memory: 12024kb
input:
100 0 10 21 9 4 1 14 0 8 1 4 6 10 0 0 4 18 0 12 5 2 5 15 1 6 2 0 4 14 5 1 2 23 1 8 1 24 8 8 9 5 2 12 2 3 7 6 11 12 12 6 12 4 4 5 0 7 4 9 12 1 7 4 7 12 2 10 2 4 8 7 1 4 0 13 9 13 2 2 3 9 14 7 9 15 10 10 6 2 12 3 11 6 3 4 7 9 6 11 1
output:
2 2 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok single line: '2 2 3 4 4 4 4 4 4 4 4 4 4 4 4 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '
Test #3:
score: 0
Accepted
time: 72ms
memory: 30396kb
input:
100000 127 145 474 139 36 135 75 670 76 433 206 214 283 56 214 440 147 280 244 190 181 565 31 550 261 93 526 404 125 390 17 552 5 364 53 337 52 506 277 279 15 248 46 61 826 69 166 297 171 289 150 175 111 151 317 342 166 13 199 152 308 19 156 347 205 166 45 115 177 235 422 425 109 4 658 232 347 370 4...
output:
2 2 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 ...
result:
ok single line: '2 2 3 3 3 3 3 3 3 3 4 4 4 4 4 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '
Test #4:
score: 0
Accepted
time: 68ms
memory: 32056kb
input:
100000 360 34 204 156 183 404 21 3 20 122 170 193 347 144 51 464 94 265 190 88 284 437 538 392 661 397 839 208 83 191 42 16 194 515 374 53 617 502 307 504 348 175 219 63 2 130 289 223 135 440 284 189 104 142 87 117 316 218 301 14 87 405 293 489 763 197 678 196 173 96 257 17 190 525 243 161 220 178 8...
output:
2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 ...
result:
ok single line: '2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '
Test #5:
score: 0
Accepted
time: 69ms
memory: 30796kb
input:
100000 322 408 29 271 168 161 265 412 230 177 325 60 331 226 298 143 343 83 274 706 47 234 287 46 329 248 174 351 235 38 172 171 251 355 274 307 468 11 222 309 666 137 18 440 1209 7 103 354 496 336 183 602 240 316 442 253 32 486 308 18 115 125 110 65 268 502 148 793 91 759 313 269 31 63 250 90 143 6...
output:
2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 ...
result:
ok single line: '2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '
Test #6:
score: 0
Accepted
time: 41ms
memory: 25408kb
input:
100000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok single line: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '
Test #7:
score: 0
Accepted
time: 75ms
memory: 32528kb
input:
100000 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...
output:
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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:
ok single line: '2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 '
Test #8:
score: 0
Accepted
time: 62ms
memory: 32272kb
input:
100000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 10...
result:
ok single line: '2 3 4 5 6 7 8 9 10 11 12 13 14... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '