#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC optimize("conserve-stack")
#include<bits/stdc++.h>
//#define int long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define mask(i) (1<<i)
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
#define getchar_unlocked getchar
inline int scan()
{
char c = getchar_unlocked();
int x = 0;
while (c < '0' || c > '9')
{
c = getchar_unlocked();
}
while (c >= '0' && c <= '9')
{
x = (x << 1) + (x << 3) + c - '0';
c = getchar_unlocked();
}
return x;
};
void phongbeo();
const int inf = 1e9;
const int mod2 = 1e6+3;
const int mod1 = 998244353;
int add(int x,int y)
{
if(x+y>=mod2) x-=mod2;
if(x+y<0) x+=mod2;
return x+y;
}
struct icd
{
long double a;
int b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a, b, c, d;
};
struct ie
{
int a, b, c, d, e;
};
int n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2, r2, center;
int i, s10, s12,k1,k2,k3,s11,limit,w,l,r,last,root;
int kk,invf;
int el = 19;
main()
{
if(fopen(task".inp","r"))
{
fin(task);
fou(task);
}
NHP
/// cin>>s1;
///modwwe
phongbeo();
// checktime
}
int a[100001];
struct IT
{
ib t[400001];
int t2[400001];
ib mer(ib a,ib b)
{
if(a.a>=b.a) return a;
return b;
}
void ff(int x)
{
for(int i=x*2;i<=x*2+1;i++)
{
t2[i]+=t2[x];
t[i].a+=t2[x];
}
t2[x]=0;
}
void build(int node,int l,int r)
{
if(l==r)
{
t[node]= {a[l],l};
return;
}
int mid=l+r>>1;
build(node<<1,l,mid);
build(node<<1|1,mid+1,r);
t[node]=mer(t[node<<1],t[node<<1|1]);
}
void upd(int node,int l,int r,int l1,int r1)
{
if(l>r1||r<l1) return;
if(l>=l1&&r<=r1)
{
t2[node]++;
t[node].a++;
return;
}
if(t2[node]!=0)ff(node);
int mid=l+r>>1;
upd(node<<1,l,mid,l1,r1);
upd(node<<1|1,mid+1,r,l1,r1);
t[node]=mer(t[node<<1],t[node<<1|1]);
}
ib get(int node,int l,int r,int l1,int r1)
{
if(l>r1||r<l1) return {0,0};
if(l>=l1&&r<=r1) return t[node];
int mid=l+r>>1;
if(t2[node]!=0)ff(node);
return mer(get(node<<1,l,mid,l1,r1),get(node<<1|1,mid+1,r,l1,r1));
}
int walk(int node,int l,int r,int x)
{
if(x>t[1].a)return n+1;
if(l==r) return l;
int mid=l+r>>1;
if(t2[node]!=0)ff(node);
if(t[node<<1].a>=x) return walk(node<<1,l,mid,x);
return walk(node<<1|1,mid+1,r,x);
}
} st;
void add()
{
cin>>l>>r;
l--;
if(r>st.t[1].a) return;
r=st.walk(1,1,n,r);
if(r+l>=n)
{
st.upd(1,1,n,r,n);
return;
}
ib x=st.get(1,1,n,1,r+l);
s3=st.walk(1,1,n,x.a+1)-1;
s5=max(r+l-x.b+1,k);
st.upd(1,1,n,s3-s5+1,s3);
if(x.b-1>=r)
st.upd(1,1,n,r,x.b-1);
}
void get()
{
cin>>l>>r;
r++;
l=st.walk(1,1,n,l);
r=st.walk(1,1,n,r)-1;
cout<<r-l+1,down
}
void phongbeo()
{
cin>>n>>m;
for(int i=1; i<=n; i++)
cin>>a[i];
sort(a+1,a+1+n);
st.build(1,1,n);
for(int i=1; i<=m; i++)
{
char hihi;
cin>>hihi;
if(hihi=='F')
add();
else get();
}
}
Compilation message
grow.cpp:71:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
71 | main()
| ^~~~
grow.cpp: In member function 'void IT::build(int, int, int)':
grow.cpp:111:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
111 | int mid=l+r>>1;
| ~^~
grow.cpp: In member function 'void IT::upd(int, int, int, int, int)':
grow.cpp:126:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
126 | int mid=l+r>>1;
| ~^~
grow.cpp: In member function 'ib IT::get(int, int, int, int, int)':
grow.cpp:135:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
135 | int mid=l+r>>1;
| ~^~
grow.cpp: In member function 'int IT::walk(int, int, int, int)':
grow.cpp:143:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
143 | int mid=l+r>>1;
| ~^~
grow.cpp: In function 'int main()':
grow.cpp:13:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | #define fin(x) freopen(x".inp","r",stdin)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
grow.cpp:75:9: note: in expansion of macro 'fin'
75 | fin(task);
| ^~~
grow.cpp:14:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | #define fou(x) freopen(x".out","w",stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
grow.cpp:76:10: note: in expansion of macro 'fou'
76 | fou(task);
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
5200 KB |
Output is correct |
2 |
Correct |
65 ms |
5704 KB |
Output is correct |
3 |
Correct |
29 ms |
5712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
26 ms |
1784 KB |
Output is correct |
6 |
Correct |
30 ms |
1920 KB |
Output is correct |
7 |
Correct |
4 ms |
844 KB |
Output is correct |
8 |
Correct |
14 ms |
1360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
1872 KB |
Output is correct |
2 |
Correct |
32 ms |
1872 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
17 ms |
1612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
2140 KB |
Output is correct |
2 |
Correct |
32 ms |
1872 KB |
Output is correct |
3 |
Correct |
5 ms |
592 KB |
Output is correct |
4 |
Correct |
32 ms |
1900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
4536 KB |
Output is correct |
2 |
Correct |
61 ms |
5192 KB |
Output is correct |
3 |
Correct |
10 ms |
3408 KB |
Output is correct |
4 |
Correct |
26 ms |
5200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
5088 KB |
Output is correct |
2 |
Correct |
60 ms |
5452 KB |
Output is correct |
3 |
Correct |
28 ms |
5508 KB |
Output is correct |
4 |
Correct |
10 ms |
3408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
5236 KB |
Output is correct |
2 |
Correct |
50 ms |
5200 KB |
Output is correct |
3 |
Correct |
29 ms |
5508 KB |
Output is correct |
4 |
Correct |
10 ms |
3408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
5704 KB |
Output is correct |
2 |
Correct |
62 ms |
5328 KB |
Output is correct |
3 |
Correct |
19 ms |
4688 KB |
Output is correct |
4 |
Correct |
33 ms |
5200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
5448 KB |
Output is correct |
2 |
Correct |
61 ms |
5588 KB |
Output is correct |
3 |
Correct |
86 ms |
5960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
6216 KB |
Output is correct |