QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#109162 | #6528. Sequence | _yjh | 20 | 1947ms | 78936kb | C++98 | 4.1kb | 2023-05-27 17:33:35 | 2023-05-27 17:33:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
inline ll read() {
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)) {if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)) {x=x*10+ch-48;ch=getchar();}
return x*f;
}
int maxx(int a,int b) {
if(a>b) return a;
return b;
}
int minn(int a,int b) {
if(a>b) return b;
return a;
}
const ll MAXN=500005;
int n,cnt,a[MAXN],b[MAXN],nw[MAXN];
map <int,int> mp;
vector <int> p[MAXN];
struct range {
int l,r;
void add(int a) {
if(a<l) l--;
else r++;
// l=minn(l,a),r=maxx(r,a);
}
};
range merge(range a,range b) {
return (range){a.l+b.l,a.r+b.r};
}
struct SGTree {
#define lc t<<1
#define rc t<<1|1
struct Node {
int mx,mn,lz;
}nd[4*MAXN];
void pushup(int t) {
nd[t].mx=maxx(nd[lc].mx,nd[rc].mx);
nd[t].mn=minn(nd[lc].mn,nd[rc].mn);
}
void pushdown(int t) {
if(nd[t].lz) {
nd[lc].mn+=nd[t].lz;
nd[rc].mn+=nd[t].lz;
nd[lc].mx+=nd[t].lz;
nd[rc].mx+=nd[t].lz;
nd[lc].lz+=nd[t].lz;
nd[rc].lz+=nd[t].lz;
nd[t].lz=0;
}
}
void Build(int t,int l,int r) {
nd[t].lz=0;
if(l==r) {
nd[t].mx=nd[t].mn=l;
return ;
}
int mid=(l+r)>>1;
Build(lc,l,mid);
Build(rc,mid+1,r);
pushup(t);
}
void build() {
Build(1,1,n);
}
void Update(int t,int l,int r,int ll,int rr,int k) {
if(ll<=l&&r<=rr) {
nd[t].mx+=k;
nd[t].mn+=k;
nd[t].lz+=k;
return ;
}
pushdown(t);
int mid=(l+r)>>1;
if(ll<=mid) Update(lc,l,mid,ll,rr,k);
if(rr>=mid+1) Update(rc,mid+1,r,ll,rr,k);
pushup(t);
}
void upd(int p,int k) {
if(nw[p]==k) return ;
Update(1,1,n,p,n,(k-nw[p]));
nw[p]=k;
}
int mx,mn;
void QPOS(int t,int l,int r,int p) {
if(l==r) {
mx=nd[t].mx,mn=nd[t].mn;
return ;
}
pushdown(t);
int mid=(l+r)>>1;
if(p<=mid) QPOS(lc,l,mid,p);
else QPOS(rc,mid+1,r,p);
}
void Query(int t,int l,int r,int ll,int rr) {
if(ll<=l&&r<=rr) {
mx=maxx(mx,nd[t].mx);
mn=minn(mn,nd[t].mn);
return ;
}
pushdown(t);
int mid=(l+r)>>1;
if(ll<=mid) {
if(nd[lc].mn>=mn&&nd[lc].mx<=mx);
else Query(lc,l,mid,ll,rr);
}
if(rr>=mid+1) {
if(nd[rc].mn>=mn&&nd[rc].mx<=mx);
else Query(rc,mid+1,r,ll,rr);
}
}
void init() {
mx=-(n+1),mn=(n+1);
}
int qsum(int l,int r) {
if(l>r) return 0;
int sum=0;
init();
QPOS(1,1,n,r);
sum+=mx;
if(l!=1) {
init();
QPOS(1,1,n,l-1);
sum-=mx;
}
return sum;
}
range qsuf(int x) {
range ans=(range){0,0};
if(!x) return ans;
int sum=qsum(1,x);
init();
Query(1,1,n,1,x);
ans.l=mn,ans.r=mx;
ans.add(0);
int tl=sum-ans.r,tr=sum-ans.l;
ans.l=tl,ans.r=tr;
return ans;
}
range qpre(int x) {
range ans=(range){0,0};
if(x==n+1) return ans;
int sum=qsum(1,x-1);
init();
Query(1,1,n,x,n);
ans.l=mn-sum,ans.r=mx-sum;
ans.add(0);
return ans;
}
bool judge(int x,int l,int r) {
range nw=merge(qsuf(l-1),qpre(r+1));
int sum=qsum(l,r);
nw.l+=sum,nw.r+=sum;
if(nw.r<=0) return x>=(-nw.r);
if(nw.l>=0) return x>=nw.l;
return 1;
}
}sgt;
bool check(int num,int x) {
int sz=p[num].size();
for(int i=0;i<sz;i++) {
if(i<x) sgt.upd(p[num][i],0);
else sgt.upd(p[num][i],1);
}
for(int l=0;l+x-1<sz;l++) {
int r=l+x-1;
sgt.upd(p[num][r],0);
if(sgt.judge(x,p[num][l],p[num][r])) return true;
sgt.upd(p[num][l],-1);
}
return false;
}
void clear(int x) {
int sz=p[x].size();
for(int i=0;i<sz;i++) sgt.upd(p[x][i],-1);
}
int solve() {
sgt.build();
int fans=1;
for(int i=1;i<=n;i++) nw[i]=1;
for(int i=1;i<=cnt;i++) {
int sz=p[i].size();
int l=fans+1,r=sz,ans=-1;
while(l<=r) {
int mid=(l+r)>>1;
if(check(i,mid)) l=mid+1,ans=mid;
else r=mid-1;
}
fans=max(fans,ans);
clear(i);
// if(clock()/CLOCKS_PER_SEC>1.97) return fans;
}
return fans;
}
int sequence(int N, std::vector<int> A) {
n=N;
for(int i=1;i<=n;i++) a[i]=b[i]=A[i-1];
sort(b+1,b+n+1);
for(int i=1;i<=n;i++) if(b[i]!=b[i-1]) mp[b[i]]=++cnt;
for(int i=1;i<=n;i++) {
a[i]=mp[a[i]];
p[a[i]].push_back(i);
}
return solve();
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 11
Accepted
time: 2ms
memory: 22072kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 98 92 89 9 86 80 6 42 20 84 82 46 56 52 30 44 39 35 82 57 33 18 38 32 63 27 55 33 44 41 39 62 26 46 59 21 85 36 60 7 36 50 22 87 83 71 27 4 3 87 47 17 62 70 24 9 20 81 21 57 50 13 32 68 70 11 95 5 56 64 90 47 42 44 72 71 46 84 72 56 63 37 35 80 78 4 54 74 79 ...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 3
result:
ok
Test #2:
score: 0
Accepted
time: 2ms
memory: 22072kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 96 1 6 1 4 6 2 5 1 1 2 8 2 4 4 1 9 8 9 8 5 3 6 6 4 9 4 2 8 8 8 2 9 1 3 6 6 1 6 5 5 3 7 9 7 1 8 5 6 8 5 1 1 4 9 6 7 2 6 6 7 4 2 2 8 5 6 4 8 2 6 5 8 6 1 6 2 1 3 4 6 3 6 8 2 5 7 8 2 4 1 5 6 2 3 6 6
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 18
result:
ok
Test #3:
score: -11
Wrong Answer
time: 0ms
memory: 22112kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 99 1 3 5 1 2 4 1 3 4 1 5 5 3 1 1 4 2 1 4 5 5 4 1 4 4 2 1 2 2 1 5 2 4 2 1 5 1 3 3 4 3 2 3 1 3 2 2 4 1 5 4 2 2 2 4 5 3 4 3 2 3 4 5 4 5 1 2 2 2 5 3 1 3 5 1 2 1 2 1 2 3 1 4 4 4 5 3 3 3 5 1 3 4 2 4 4 2 1 2
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 20
result:
wrong answer 1st lines differ - on the 1st token, expected: '19', found: '20'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 7
Accepted
Test #20:
score: 7
Accepted
time: 266ms
memory: 64752kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 499996 53 78 81 111 119 124 126 130 164 175 219 227 233 249 282 298 332 341 348 436 437 448 452 455 462 465 495 535 557 558 576 600 620 627 632 642 643 659 695 696 713 730 743 805 816 865 869 872 875 882 883 902 924 937 990 998 1025 1092 1137 1145 1166 1176 1...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 8
result:
ok
Test #21:
score: 0
Accepted
time: 303ms
memory: 64612kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 499996 5 7 11 19 19 19 19 23 23 27 29 31 32 33 34 37 37 40 45 49 53 57 67 69 70 76 79 80 82 82 84 89 91 96 105 109 109 109 110 111 112 113 116 119 120 121 122 129 133 135 136 142 145 147 148 151 155 160 161 162 162 171 174 177 178 179 180 181 185 189 191 192 ...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 9
result:
ok
Test #22:
score: 0
Accepted
time: 755ms
memory: 42020kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 500000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 100281
result:
ok
Test #23:
score: 0
Accepted
time: 267ms
memory: 62160kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 500000 1 7 8 11 15 17 18 19 19 20 22 24 29 33 33 35 37 39 46 47 48 49 49 49 52 54 57 60 60 62 62 63 68 70 71 72 72 78 79 79 85 86 86 92 94 94 97 99 100 100 106 108 110 114 116 118 119 122 125 127 128 133 133 134 136 137 144 144 145 148 152 153 153 153 160 161...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 9
result:
ok
Test #24:
score: 0
Accepted
time: 265ms
memory: 60188kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 499996 18 24 36 39 56 61 85 128 159 164 225 240 252 254 258 263 313 365 387 387 396 439 443 476 481 489 509 526 547 582 583 584 631 635 645 673 679 699 709 724 728 731 741 757 768 785 785 817 827 828 834 836 846 851 858 864 892 900 908 920 920 922 929 962 989...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 11
result:
ok
Test #25:
score: 0
Accepted
time: 179ms
memory: 42164kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 499996 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 8818
result:
ok
Test #26:
score: 0
Accepted
time: 1045ms
memory: 42524kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 500000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 7068
result:
ok
Test #27:
score: 0
Accepted
time: 210ms
memory: 40000kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 499998 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 176759
result:
ok
Subtask #4:
score: 0
Time Limit Exceeded
Test #28:
score: 12
Accepted
time: 180ms
memory: 40124kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 499999 2 1 2 2 2 1 2 3 1 3 1 2 2 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 1 1 1 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 3 3 3 3 1 3 1 2 2 1 1 1 3 1 3 1 1 2 1 2 2 2 1 3 2 1 1 1 2 2 1 2 2 3 1 2 2 1 2 2 1 1 2 1 1 2 2 1 2 2 1 1 1 1 2 2 1 1 1 1 1 2 1 1 2 1 1 3 2 1 1 1 3 1 1 2 1 3 1 1 ...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 277713
result:
ok
Test #29:
score: 0
Accepted
time: 1947ms
memory: 41968kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 499999 2 3 1 3 3 3 1 2 3 3 3 2 2 1 1 3 1 2 1 3 3 3 2 2 2 2 3 3 2 2 2 1 1 2 3 3 1 3 1 1 2 3 3 1 1 1 2 1 1 1 2 3 2 2 1 2 1 1 3 1 1 1 3 1 1 2 1 3 2 3 1 3 1 3 3 2 1 3 1 2 1 3 2 1 1 2 3 1 2 1 3 3 1 2 1 3 3 3 2 3 2 1 1 2 1 2 3 1 1 2 2 1 3 2 3 2 3 2 2 1 3 2 3 1 3 3 ...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 166105
result:
ok
Test #30:
score: -12
Time Limit Exceeded
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 499997 3 1 2 1 1 1 1 3 2 1 2 2 3 2 2 3 3 3 3 3 1 1 2 1 3 2 1 1 2 2 3 1 1 2 1 3 2 2 1 2 1 3 3 2 2 1 3 1 3 2 2 3 3 2 3 1 2 3 2 1 3 2 2 1 3 2 3 2 1 3 3 1 2 1 1 2 1 2 3 1 2 3 1 3 2 3 3 1 3 1 2 1 3 2 1 3 1 2 1 2 2 1 1 2 2 1 3 3 2 3 1 3 3 3 2 1 1 2 2 2 1 1 2 1 1 2 ...
output:
Unauthorized output
result:
Subtask #5:
score: 13
Accepted
Test #33:
score: 13
Accepted
time: 572ms
memory: 78892kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 499999 490225 471440 499001 369862 494577 479599 486292 476071 471988 486939 482356 482290 497141 488452 495446 494292 404798 493826 482595 481107 447196 477441 418064 495941 448927 483365 418585 489220 443224 482574 487957 467944 493253 472016 475543 442250 ...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 1
result:
ok
Test #34:
score: 0
Accepted
time: 578ms
memory: 78936kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 499999 490225 471440 499001 369862 494577 479599 486292 476071 471988 486939 482356 482290 497141 488452 495446 494292 404798 493826 482595 481107 447196 477441 418064 495941 448927 483365 418585 489220 443224 482574 487957 467944 493253 472016 475543 442250 ...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 1
result:
ok
Test #35:
score: 0
Accepted
time: 620ms
memory: 75456kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 499999 8693 471440 17469 369862 13045 479599 4760 476071 471988 5407 824 758 15609 6920 13914 12760 404798 12294 1063 481107 447196 477441 418064 14409 448927 1833 418585 7688 443224 1042 6425 467944 11721 472016 475543 442250 17475 477814 477933 468083 40726...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 2
result:
ok
Test #36:
score: 0
Accepted
time: 604ms
memory: 75644kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 499999 8693 471440 17469 369862 13045 479599 4760 476071 471988 5407 824 758 15609 6920 13914 12760 404798 12294 1063 481107 447196 477441 418064 14409 448927 1833 418585 7688 443224 1042 6425 467944 11721 472016 475543 442250 17475 477814 477933 468083 40726...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 2
result:
ok
Test #37:
score: 0
Accepted
time: 531ms
memory: 67064kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 500000 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 ...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 2
result:
ok
Test #38:
score: 0
Accepted
time: 534ms
memory: 67176kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 500000 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 ...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 1
result:
ok
Test #39:
score: 0
Accepted
time: 414ms
memory: 66332kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 500000 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 ...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 1
result:
ok
Test #40:
score: 0
Accepted
time: 368ms
memory: 65544kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 500000 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 ...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 2
result:
ok
Subtask #6:
score: 0
Skipped
Dependency #2:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%