# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
649854 |
2022-10-11T12:50:33 Z |
rsjw |
Growing Trees (BOI11_grow) |
C++17 |
|
1000 ms |
2720 KB |
#include <bits/stdc++.h>
using namespace std;
int n;
int t[100010],a[100010];
void update(int x,int I) {
while(x<=n) t[x]+=I,x+=x&-x;
}
int query(int x) {
int ans=0; while(x) ans+=t[x],x-=x&-x; return ans;
}
//写个假的二分
int search_lower(int x) { //第一个大于等于x
int l=1,r=n,mid;
while(l<=r) {
mid=(l+r)/2;
if(query(mid)<x) l=mid+1;
else r=mid-1;
}
return r+1;
}
int search_upper(int x) { //第一个大于x
int l=1,r=n,mid;
while(l<=r) {
mid=(l+r)/2;
if(query(mid)<=x) l=mid+1;
else r=mid-1;
}
return r+1;
}
int main() {
int m,i,j;
char c;
int x,y,t,t2;
cin>>n>>m;
for(i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+n+1);
for(i=1;i<=n;i++) update(i,a[i]-a[i-1]);
for(i=1;i<=m;i++) {
cin>>c>>x>>y;
if(c=='F') {
t=search_lower(y);
update(t,1);
update(t+x-1,-1);
t2=search_upper(query(t+x-1))-1;
update(t2,1);
update(t2+1,-1);
} else cout<<search_upper(y)-search_lower(x)<<endl;
}
return 0;
}
Compilation message
grow.cpp: In function 'int main()':
grow.cpp:31:10: warning: unused variable 'j' [-Wunused-variable]
31 | int m,i,j;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
27 ms |
2220 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1073 ms |
780 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1071 ms |
436 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1074 ms |
1228 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
30 ms |
1996 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1056 ms |
1228 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
32 ms |
2472 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
40 ms |
2372 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
35 ms |
2720 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |