ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#200233 | #3470. 寻找好点 | BYR_KKK | 100 | 7456ms | 87088kb | C++ | 1.9kb | 2023-12-31 09:29:04 | 2023-12-31 12:11:20 |
answer
#include<bits/stdc++.h>
#define int long long
#define ok std::printf("OrzFinderHT\n")
#define pr std::printf
int read(){
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9') x=x*10+(int)(c-'0'),c=getchar();
return x*f;
}
const int maxn=1e6+10;
int a[maxn];
struct tree{
int l,r,ls,rs,mx;
}s[maxn*2];
int cnt=0;
void push_up(int p){
s[p].mx=std::max(s[s[p].ls].mx,s[s[p].rs].mx);
return ;
}
int build(int l,int r){
int p=++cnt;
s[p].l=l,s[p].r=r;
if(l==r){
s[p].mx=a[l];
return p;
}
int mid=(l+r)>>1;
s[p].ls=build(l,mid);
s[p].rs=build(mid+1,r);
push_up(p);
return p;
}
void update(int p,int k,int x){
int l=s[p].l,r=s[p].r;
if(l==r&&l==k){
s[p].mx=x;
return ;
}
int mid=(l+r)>>1;
if(k<=mid) update(s[p].ls,k,x);
else update(s[p].rs,k,x);
push_up(p);
return ;
}
int query(int p,int L,int R,int x){
int l=s[p].l,r=s[p].r;
if(r<L||l>R) return -1;
//; ok;
if(s[p].mx<=x) return -1;
// ok;
if(l==r) {
if(s[p].mx>x) return l;
return -1;
}
int ls=s[p].ls,rs=s[p].rs;
int mid=(l+r)>>1;
// ok;
if(l>=L&&r<=R){
if(s[ls].mx>x){
return query(ls,L,R,x);
}
if(s[rs].mx>x){
return query(rs,L,R,x);
}
return -1;
}
//包含
if(l<=L&&r>=R){
int als=query(ls,L,R,x),ars=query(rs,L,R,x);
// pr("%lld %lld %lld %lld\n",l,r,als,ars);
if(als!=-1) return als;
return ars;
}
if(l<L&&R>=r){
int als=query(ls,L,R,x),ars=query(rs,L,R,x);
if(als!=-1) return als;
return ars;
}
int als=query(ls,L,R,x),ars=query(rs,L,R,x);
if(als!=-1) return als;
return ars;
}
signed main(){
int n=read();
for(int i=1;i<=n;i++) a[i]=read();
build(1,n);
int q=read();
while(q--){
int l=read(),r=read(),k=read();
int loc=query(1,l,r,k);
std::printf("%lld\n",loc);
if(loc==-1) continue;
update(1,loc,k);
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 1ms
memory: 1180kb
input:
300 246 733 1322 2465 2613 3452 4124 4346 4368 4871 5995 6637 7297 7634 7507 8383 8979 9620 10757 11...
output:
148 178 225 190 138 179 69 147 83 200 99 192 19 79 200 100 120 148 -1 282 57 134 141 142 198 151 190...
result:
ok 300 lines
Test #2:
score: 10
Accepted
time: 0ms
memory: 1176kb
input:
300 493 1451 2459 2622 3230 3690 3979 4574 5081 5631 6458 6215 7727 6712 7752 7904 10559 10395 9721 ...
output:
147 233 156 89 194 233 11 245 222 120 188 71 109 169 137 82 122 134 105 160 155 50 187 240 -1 94 134...
result:
ok 300 lines
Test #3:
score: 10
Accepted
time: 3ms
memory: 1584kb
input:
5000 9 20 45 52 49 57 58 87 110 114 104 119 130 126 176 144 198 211 229 234 199 251 215 260 240 293 ...
output:
-1 4025 -1 2859 799 3670 2568 1368 2950 1598 2548 956 3217 3063 -1 -1 2744 3604 1392 515 1040 -1 210...
result:
ok 5000 lines
Test #4:
score: 10
Accepted
time: 4ms
memory: 1580kb
input:
5000 9 11 22 36 56 62 67 80 96 98 117 118 134 139 144 158 174 182 190 203 227 232 247 244 259 268 29...
output:
-1 -1 1724 -1 2593 -1 939 -1 -1 -1 1503 -1 2163 2578 1527 2112 -1 2115 3271 3945 -1 3149 3651 1324 3...
result:
ok 5000 lines
Test #5:
score: 10
Accepted
time: 0ms
memory: 1584kb
input:
5000 10 12 39 37 58 58 82 116 119 95 138 117 144 183 174 217 197 205 209 243 211 271 286 257 236 298...
output:
-1 -1 1574 1937 1691 -1 4216 -1 1708 955 -1 3433 -1 2531 3493 1962 2115 3046 -1 799 -1 -1 3216 2821 ...
result:
ok 5000 lines
Test #6:
score: 10
Accepted
time: 4ms
memory: 1584kb
input:
5000 17 24 41 50 66 71 80 86 102 106 123 133 150 157 167 180 182 191 204 218 228 243 251 268 279 293...
output:
2066 -1 2658 2886 916 958 -1 4190 -1 -1 2858 -1 3611 2990 1167 4519 1151 -1 3881 4966 943 3101 -1 -1...
result:
ok 5000 lines
Test #7:
score: 10
Accepted
time: 2691ms
memory: 87084kb
input:
1000000 5 7 9 15 24 28 36 38 45 48 51 56 54 61 70 71 78 79 85 91 98 107 112 117 126 132 133 142 154 ...
output:
523080 585083 682099 488339 477822 330809 337824 574145 627108 434148 372632 532279 774997 474340 51...
result:
ok 1000000 lines
Test #8:
score: 10
Accepted
time: 2579ms
memory: 87088kb
input:
1000000 4 7 12 23 28 36 47 48 65 70 73 82 86 87 97 101 111 118 122 120 124 126 137 149 151 148 158 1...
output:
436413 406778 507867 967432 462532 574431 725838 409960 532986 556972 615602 229720 269321 154974 26...
result:
ok 1000000 lines
Test #9:
score: 10
Accepted
time: 1066ms
memory: 87084kb
input:
1000000 8 8 17 27 28 36 53 51 60 69 72 76 83 81 91 87 97 103 115 118 118 132 140 143 152 154 160 156...
output:
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 3...
result:
ok 1000000 lines
Test #10:
score: 10
Accepted
time: 1108ms
memory: 87084kb
input:
1000000 8 9 16 19 23 34 38 39 47 54 58 64 71 83 85 94 98 109 109 112 118 120 132 144 146 145 139 153...
output:
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 3...
result:
ok 1000000 lines
Extra Test:
score: 0
Extra Test Passed