ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#200214 | #3470. 寻找好点 | LDM0116 | 100 | 6182ms | 38116kb | C++11 | 2.5kb | 2023-12-31 09:18:10 | 2023-12-31 12:06:33 |
answer
#include<bits/stdc++.h>
#define ll long long
#define mkp make_pair
#define gc() (p1==p2&&(p2=(p1=b)+fread(b,1,n,stdin),p1==p2)?EOF:*p1++)
#define inf 0x3f3f3f3f
using namespace std;
namespace r{
const int n=10000000;
char *p1,*p2,b[n];
inline int read(){
int x=0,f=1;
char c=gc();
while(!isdigit(c)){
if(c==45) f=-1;
c=gc();
}
while(isdigit(c)){
x=(x<<1)+(x<<3)+c-'0';
c=gc();
}
return x*f;
}
random_device r;
mt19937 rd(r());
inline int rand(int l,int r){
return uniform_int_distribution<int>(l,r)(rd);
}
}
using namespace r;
namespace w{
const int s=10000000;
char b[s];
int cnt=0;
inline void write(int x){
if(x<0){
x=-x;
b[cnt++]=45;
if(cnt==s) fwrite(b,1,cnt,stdout),cnt=0;
}
if(x>9) write(x/10);
b[cnt++]=(x%10)|48;
if(cnt==s) fwrite(b,1,cnt,stdout),cnt=0;
}
inline void space(){
b[cnt++]=' ';
if(cnt==s) fwrite(b,1,cnt,stdout),cnt=0;
}
inline void endl(){
b[cnt++]='\n';
if(cnt==s) fwrite(b,1,cnt,stdout),cnt=0;
}
inline void show(){
if(cnt) fwrite(b,1,cnt,stdout),cnt=0;
}
}
using namespace w;
namespace ldm{
int n,v[1000001],q,ans,l,r,k;
struct node{
int maxx,maxi;
}a[4000001];
inline void pushup(int x){
if(a[x<<1].maxx>=a[x<<1|1].maxx){
a[x].maxx=a[x<<1].maxx;
a[x].maxi=a[x<<1].maxi;
}else{
a[x].maxx=a[x<<1|1].maxx;
a[x].maxi=a[x<<1|1].maxi;
}
}
inline void build(int x,int l,int r){
if(l==r){
a[x].maxx=v[l];
a[x].maxi=l;
return;
}
int mid=(l+r)>>1;
build(x<<1,l,mid);
build(x<<1|1,mid+1,r);
pushup(x);
}
inline void ef(int x,int l,int r,int L,int R){
if(r<L||l>R) return;
if(l==r){
if(a[x].maxx>k&&!ans){
ans=l;
}
return;
}
int mid=(l+r)>>1;
if(l>=L&&r<=R){
if(a[x<<1].maxx>k){
ef(x<<1,l,mid,L,R);
}else if(a[x<<1|1].maxx>k){
ef(x<<1|1,mid+1,r,L,R);
}
return;
}
ef(x<<1,l,mid,L,R);
ef(x<<1|1,mid+1,r,L,R);
}
inline void modify(int x,int l,int r,int k,int v){
if(r<k||l>k) return;
if(l==r){
a[x].maxx=v;
return;
}
int mid=(l+r)>>1;
modify(x<<1,l,mid,k,v);
modify(x<<1|1,mid+1,r,k,v);
pushup(x);
}
int main(){
n=read();
for(int i=1;i<=n;i++){
v[i]=read();
}
build(1,1,n);
q=read();
while(q--){
l=read(),r=read(),k=read();
ans=0;
ef(1,1,n,l,r);
if(!ans){
write(-1),endl();
}else{
write(ans),endl();
modify(1,1,n,ans,k);
}
}
show();
return 0;
}
}
int main(){
ldm::main();
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1256kb
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: 1256kb
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: 1516kb
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: 2ms
memory: 1516kb
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: 4ms
memory: 1512kb
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: 2ms
memory: 1512kb
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: 2201ms
memory: 38112kb
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: 2000ms
memory: 38116kb
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: 1148ms
memory: 37932kb
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: 821ms
memory: 37932kb
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