ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#200261 | #3470. 寻找好点 | jane | 100 | 5682ms | 29676kb | C++11 | 1.2kb | 2023-12-31 09:46:44 | 2023-12-31 12:17:56 |
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,q,a[N],mx;
struct node{
int x;
int l,r;
}t[N<<2];
void build(int l,int r,int p){
t[p].l=l,t[p].r=r;
if(l==r){
t[p].x=a[l];
return;
}
int mid=(l+r)>>1;
build(l,mid,(p<<1));
build(mid+1,r,(p<<1)+1);
t[p].x=max(t[p<<1].x,t[(p<<1)+1].x);
}
int gets(int l,int r,int p){
if(l<=t[p].l&&t[p].r<=r)
return t[p].x;
int mid=(t[p].l+t[p].r)>>1,res=0;
if(l<=mid)
res=max(res,gets(l,r,p<<1));
if(r>mid)
res=max(res,gets(l,r,(p<<1)+1));
return res;
}
int update(int l,int r,int p,int v){
if(t[p].x<=v)
return -1;
if(t[p].l==t[p].r&&t[p].x>v){
t[p].x=v;
return t[p].l;
}
int mid=(t[p].l+t[p].r)>>1,res=-1;
if(l<=mid&&t[p<<1].x>v)
res=update(l,r,p<<1,v);
if(res==-1&&r>mid&&t[(p<<1)+1].x>v)
res=update(l,r,(p<<1)+1,v);
t[p].x=max(t[p<<1].x,t[(p<<1)+1].x);
return res;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
build(1,n,1);
scanf("%d",&q);
while(q--){
int l,r,v;
scanf("%d%d%d",&l,&r,&v);
mx=gets(l,r,1);
if(mx<=v){
printf("-1\n");
continue;
}
printf("%d\n",update(l,r,1,v));
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1204kb
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: 1208kb
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: 4ms
memory: 1400kb
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: 1400kb
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: 5ms
memory: 1400kb
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: 3ms
memory: 1404kb
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: 1638ms
memory: 29676kb
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: 1700ms
memory: 29676kb
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: 1301ms
memory: 29676kb
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: 1027ms
memory: 29676kb
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