/*
IN THE NAME OF GOD
*/
#include <bits/stdc++.h>
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;
#define F first
#define S second
#define Mp make_pair
#define pb push_back
#define pf push_front
#define size(x) ((ll)x.size())
#define all(x) (x).begin(),(x).end()
#define kill(x) cout << x << '\n', exit(0);
#define fuck(x) cout << "(" << #x << " , " << x << ")" << endl
#define endl '\n'
const int N = 3e5+23, lg = 18;
ll Mod = 1e9+7; //998244353;
inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
ll ans = 1;
a=MOD(a, mod);
while (b) {
if (b & 1) ans = MOD(ans*a, mod);
b >>= 1;
a = MOD(a*a, mod);
}
return ans;
}
struct node {
ll out, ex;
node() {
out=ex=0;
}
} seg[2*N];
node merge(node a, node b) {
b.out += max(0ll, a.out-b.ex);
b.ex = a.ex + max(0ll, b.ex-a.out);
return b;
}
void update(int ind, ll val) {
if(ind == 0) return ;
if(ind >= (1<<lg)) {
if(val>0) seg[ind].out=val, seg[ind].ex=0;
else seg[ind].out=0, seg[ind].ex=-val;
} else {
seg[ind] = merge(seg[2*ind], seg[2*ind+1]);
}
update(ind/2, val);
}
ll sg[2*N], gr[2*N];
void upd(int ind, ll val, ll tg) {
if(ind == 0) return;
if(ind >= (1<<lg)) {
sg[ind] += val;
gr[ind] = tg;
} else {
sg[ind] = sg[2*ind] + sg[2*ind+1];
}
upd(ind/2, val, tg);
}
ll qry(int l, int r, int ind=1, int lc=1, int rc=(1<<lg)+1) {
if(lc>=r || l>=rc) return 0;
if(lc>=l && rc<=r) return sg[ind];
int mid = (lc+rc)/2;
return qry(l, r, 2*ind, lc, mid) + qry(l, r, 2*ind+1, mid, rc);
}
ll fnd(ll val, int ind=1) {
if(ind>=(1<<lg)) {
if(sg[ind] >= val) return gr[ind];
else return 0;
}
if(sg[2*ind] >= val) return fnd(val, 2*ind);
return fnd(val-sg[2*ind], 2*ind+1);
}
node query(int l, int r, int ind=1, int lc=1, int rc=(1<<lg)+1) {
if(lc>=r || l>=rc) return node();
if(lc>=l && rc<=r) return seg[ind];
int mid = (lc+rc)/2;
return merge(query(l, r, 2*ind, lc, mid), query(l, r, 2*ind+1, mid, rc));
}
ll n, m, q, ans[N], cnt;
vector<vector<ll>> vec[N];
int main () {
ios_base::sync_with_stdio(false), cin.tie(0);
cin>>n>>m>>q;
for(ll typ,l,r,c,k,a,b,i=1; i<=q; i++) {
cin>>typ;
if(typ == 1) {
cin>>l>>r>>c>>k;
vec[l].pb({1, i, c, k, 1});
vec[r+1].pb({1, i, c, k, -1});
} else if(typ == 2) {
cin>>l>>r>>k;
vec[l].pb({2, i, k, -1});
vec[r+1].pb({2, i, k, 1});
} else {
cin>>a>>b;
vec[a].pb({3, i, b, ++cnt});
}
}
for(int i=1; i<=n; i++) {
for(auto it : vec[i]) {
if(it[0]==1) {
upd(it[1]+(1<<lg)-1, it[3]*it[4], it[2]);
update(it[1]+(1<<lg)-1, it[3]*it[4]);
}
if(it[0] == 2) {
update(it[1]+(1<<lg)-1, it[2]*it[3]);
}
}
for(auto it : vec[i]) {
if(it[0] == 3) {
ll res = query(1, it[1]).out;
if(qry(1, it[1])-res+it[2] <= qry(1, it[1])) ans[it[3]] = fnd(qry(1,it[1])-res+it[2]);
else ans[it[3]] = 0;
}
}
}
for(int i=1; i<=cnt; i++) cout<<ans[i]<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
26712 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
26712 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
84 ms |
38376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
480 ms |
64852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
26712 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
93 ms |
33736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
26712 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
26712 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |