#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a))
#define MEM_1(a) memset((a),-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin())
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<ld> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };
Pll lazy[524288];
ll tree[524288];
void g(Pll &p1,Pll p2){
if(p1.Y<=p2.X){
p1.X+=p2.X-p1.Y;
p1.Y=p2.Y;
}else{
p1.Y+=p2.Y-p2.X;
}
}
void propagation(int node,int S,int E){
tree[node]=max(tree[node]-lazy[node].X,0ll)+lazy[node].Y;
if(S!=E){
int L=node<<1,R=L|1;
g(lazy[L],lazy[node]);
g(lazy[R],lazy[node]);
}
lazy[node]=mp(0,0);
}
void upd(int node,int S,int E,int i,int j,ll k){
propagation(node,S,E);
if (i>E || j<S)return;
if(i<=S && E<=j){
if(k>0)lazy[node].Y+=k;
else lazy[node].X-=k;
propagation(node,S,E);
return;
}
upd(node<<1,S,(S+E)/2,i,j,k);
upd(node<<1|1,(S+E)/2+1,E,i,j,k);
}
ll find(int node,int S,int E,int i,int j){
propagation(node,S,E);
if (i>E || j<S)return 0;
if(i<=S && E<=j)return tree[node];
return find(node<<1,S,(S+E)/2,i,j)+find(node<<1|1,(S+E)/2+1,E,i,j);
}
int t[250000],a[250000],b[250000],c[250000],ans[250000];
ll d[250000],cnt[250000];
ll tree2[524288];
void upd(int node, int S, int E, int k, ll dif){
tree2[node] += dif;
if (S == E)return;
if (k <= (S + E) / 2)upd(node * 2, S, (S + E) / 2, k, dif);
else upd(node * 2 + 1, (S + E) / 2 + 1, E, k, dif);
}
int findK(int node, int S, int E, ll k){
if (S == E)return c[S];
if (k <= tree2[node * 2])return findK(node * 2, S, (S + E) / 2, k);
return findK(node * 2 + 1, (S + E) / 2 + 1, E, k - tree2[node * 2]);
}
int main(){
int n,m,q;
scanf("%d%d%d",&n,&m,&q);
Viii E;
fup(i,0,q-1,1){
scanf("%d",t+i);
if(t[i]==1){
scanf("%d%d%d%lld",a+i,b+i,c+i,d+i);
upd(1,1,n,a[i],b[i],d[i]);
E.pb(iii(a[i],0,i));
E.pb(iii(b[i]+1,1,i));
}else if(t[i]==2){
scanf("%d%d%lld",a+i,b+i,d+i);
upd(1,1,n,a[i],b[i],-d[i]);
}else{
scanf("%d%lld",a+i,d+i);
cnt[i]=find(1,1,n,a[i],a[i]);
E.pb(iii(a[i],2,i));
}
}
sort(ALL(E));
for(auto [x,k,i]:E){
if(k==0){
upd(1,0,q-1,i,d[i]);
}else if(k==1){
upd(1,0,q-1,i,-d[i]);
}else{
ll tot=tree2[1];
if(d[i]>tot)ans[i]=0;
else{
ll K=tot-cnt[i]+d[i];
ans[i]=findK(1,0,q-1,K);
}
}
}
fup(i,0,q-1,1){
if(t[i]==3)printf("%d\n",ans[i]);
}
}
Compilation message
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
foodcourt.cpp:99:2: note: in expansion of macro 'fup'
99 | fup(i,0,q-1,1){
| ^~~
foodcourt.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
foodcourt.cpp:130:2: note: in expansion of macro 'fup'
130 | fup(i,0,q-1,1){
| ^~~
foodcourt.cpp:97:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | scanf("%d%d%d",&n,&m,&q);
| ~~~~~^~~~~~~~~~~~~~~~~~~
foodcourt.cpp:100:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
100 | scanf("%d",t+i);
| ~~~~~^~~~~~~~~~
foodcourt.cpp:102:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
102 | scanf("%d%d%d%lld",a+i,b+i,c+i,d+i);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:107:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
107 | scanf("%d%d%lld",a+i,b+i,d+i);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:110:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
110 | scanf("%d%lld",a+i,d+i);
| ~~~~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
96 ms |
8740 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
579 ms |
33420 KB |
Output is correct |
2 |
Correct |
414 ms |
29780 KB |
Output is correct |
3 |
Incorrect |
619 ms |
34848 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
110 ms |
9196 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |