This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vi vector<int>
#define vp32 vector<p32>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MOD %1000000007
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
using Tree =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//never guess
//never debug without reviewing code
//never try adding ones or substracting them
//only step by step debug when necessay
struct segtree
{
int size = 1, lazy[(int)1e6] = {0};
segtree(int n){while(size<n) size*=2;}
void upd(int l, int r){
upd(l,r,0,0,size);
}
void upd(int l, int r, int x, int lx, int rx){
if(lx>=r||rx<=l) return;
if(lx>=l&&rx<=r){
lazy[x]++;
return;
}
int m = (lx+rx)/2;
upd(l,r,2*x+1,lx,m);
upd(l,r,2*x+2,m,rx);
}
int get(int i){
return get(i,0,0,size);
}
int get(int i, int x, int l, int r){
if(r-l==1) return lazy[x];
int m = (r+l)/2;
int res;
if(i<m) res = get(i,2*x+1,l,m);
else res = get(i,2*x+2,m,r);
return res+lazy[x];
}
};
int main()
{
fast_cin();
#ifndef ONLINE_JUDGE
#ifdef _WIN32
freopen("input.in", "r", stdin);
freopen("input.out", "w", stdout);
#endif
#endif
int n,m; cin>>n>>m;
int arr [n];
for(int & sub : arr){
cin>>sub;
}
segtree sgt(n);
sort(arr,arr+n);
for (size_t i = 0; i < m; i++)
{
char t; cin>>t;
if(t=='F'){
int h,c; cin>>c>>h;
//binary search the element with at least h
int l = -1, r = n;
while(r-l>1){
int mid = (r+l)/2;
if(sgt.get(mid)+arr[mid]<h) l = mid;
else r = mid;
}
if(r+c-1>n-1) c = n-r;
int last_tree = r+c-1;
//binary search the index with value strictly less than the value of r
int la = -1, ra = n;
while(ra-la>1){
int mid = (ra+la)/2;
if(sgt.get(mid)+arr[mid]>=sgt.get(last_tree)+arr[last_tree]) ra = mid;
else la = mid;
}
int done = la+1-r;
if(la>=r) sgt.upd(r,la + 1);
else done = 0;
//binary search largest index with value not greater than r;
la = 0, ra = n;
while(ra-la>1){
int mid = (ra+la)/2;
if(sgt.get(mid)+arr[mid]>sgt.get(last_tree)+arr[last_tree]) ra = mid;
else la = mid;
}
sgt.upd(la+1+done-c,la+1);
}
else{
int mn, mx; cin>>mn>>mx;
int l = -1, r = n;
while(r-l>1){
int mid = (r+l)/2;
if(arr[mid]+sgt.get(mid)<mn) l = mid;
else r = mid;
}
int p = r;
l = -1, r = n;
while(r-l>1){
int mid = (r+l)/2;
if(arr[mid]+sgt.get(mid)<=mx) l = mid;
else r = mid;
}
cout<<r-p<<'\n';
}
}
return 0;
}
Compilation message (stderr)
grow.cpp: In function 'int main()':
grow.cpp:73:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
73 | for (size_t i = 0; i < m; i++)
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |