#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define fi first
#define se second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
struct pair_hash{
size_t operator()(const pair<int,int>&x)const{
return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
}
};
const ll INF = 1e18;
struct Update{
int type, tm, mode;
ll x;
Update(int nt, int ntime, ll nx){
type = nt;
tm = ntime;
x = nx;
mode = 1;
}
};
struct Node{
ll mx, mn, lazyMx, lazyMn;
Node(){
mn = mx = lazyMx = lazyMn = 0LL;
}
Node(ll nx, ll nn, ll lx, ll ln){
mx = nx;
mn = nn;
lazyMx = lx;
lazyMn = ln;
}
};
const int MAXN = 2e5 + 7;
const int BASE = (1 << 18);
int ans[MAXN];
int C[MAXN];
vector<Update> updates[MAXN];
vector<pair<int, ll>> queries[MAXN];//czas, Bi
Node tree[2 * BASE + 7];
int xd67[MAXN];
int n, m, q;
void Push(int v){
tree[2 * v].mn += tree[v].lazyMn;
tree[2 * v].lazyMn += tree[v].lazyMn;
tree[2 * v + 1].mn += tree[v].lazyMn;
tree[2 * v + 1].lazyMn += tree[v].lazyMn;
tree[v].lazyMn = 0LL;
tree[2 * v].mx += tree[v].lazyMx;
tree[2 * v].lazyMx += tree[v].lazyMx;
tree[2 * v + 1].mx += tree[v].lazyMx;
tree[2 * v + 1].lazyMx += tree[v].lazyMx;
tree[v].lazyMx = 0LL;
}
Node merge(Node a, Node b){
Node res;
res.mn = min(a.mn, b.mn);
res.mx = max(a.mx, b.mx);
return res;
}
int find(int v, int l, int p, ll val){
if(l == p){
return v - BASE;
}
Push(v);
int mid = (l + p) / 2;
int ret;
if(tree[2 * v].mx >= val){
ret = find(2 * v, l, mid, val);
}else{
ret = find(2 * v + 1, mid + 1, p, val);
}
tree[v] = merge(tree[2 * v], tree[2 * v + 1]);
return ret;
}
ll queryMn(int v, int l, int p, int a, int b){
if(p < a || b < l){
return INF;
}
if(a <= l && p <= b){
return tree[v].mn;
}
Push(v);
int mid = (l + p) / 2;
ll ret = min(queryMn(2 * v, l, mid, a, b), queryMn(2 * v + 1, mid + 1, p, a, b));
tree[v] = merge(tree[2 * v], tree[2 * v + 1]);
return ret;
}
ll queryMx(int v, int l, int p, int a, int b){
if(p < a || b < l){
return 0LL;
}
if(a <= l && p <= b){
return tree[v].mx;
}
Push(v);
int mid = (l + p) / 2;
ll ret = max(queryMx(2 * v, l, mid, a, b), queryMx(2 * v + 1, mid + 1, p, a, b));
tree[v] = merge(tree[2 * v], tree[2 * v + 1]);
return ret;
}
void updMx(int v, int l, int p, int a, int b, ll val){
if(p < a || b < l){
return;
}
if(a <= l && p <= b){
tree[v].mx += val;
tree[v].lazyMx += val;
return;
}
Push(v);
int mid = (l + p) / 2;
updMx(2 * v, l, mid, a, b, val);
updMx(2 * v + 1, mid + 1, p, a, b, val);
tree[v] = merge(tree[2 * v], tree[2 * v + 1]);
}
void updMn(int v, int l, int p, int a, int b, ll val){
if(p < a || b < l){
return;
}
if(a <= l && p <= b){
tree[v].mn += val;
tree[v].lazyMn += val;
return;
}
Push(v);
int mid = (l + p) / 2;
updMn(2 * v, l, mid, a, b, val);
updMn(2 * v + 1, mid + 1, p, a, b, val);
tree[v] = merge(tree[2 * v], tree[2 * v + 1]);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m >> q;
for(int i = 1; i <= q; i++){
int type;
cin >> type;
xd67[i] = type;
if(type == 1){
int l, r;
ll K;
cin >> l >> r >> C[i] >> K;
Update curr = Update(type, i, K);
updates[l].pb(curr);
curr.mode = -1;
updates[r + 1].pb(curr);
}else if(type == 2){
int l, r;
ll K;
cin >> l >> r >> K;
Update curr = Update(type, i, K);
updates[l].pb(curr);
curr.mode = -1;
updates[r + 1].pb(curr);
}else{
int ind;
ll x;
cin >> ind >> x;
queries[ind].pb(mp(i, x));
}
}
for(int i = 1; i <= n; i++){
// cerr << "===== " << i << '\n';
// cerr << "UPD: \n";
for(auto curr : updates[i]){
// cerr << curr.mode << ' ' << curr.tm << '\n';
updMn(1, 0, BASE - 1, curr.tm, q, curr.x * curr.mode * (curr.type == 1 ? 1 : -1));
if(curr.type == 1){
updMx(1, 0, BASE - 1, curr.tm, q, curr.x * curr.mode);
}
}
// cerr << "queries\n";
for(auto [id, x] : queries[i]){
// cerr << queryMn(1, 0, BASE - 1, id, id) << '\n';
// cerr << queryMn(1, 0, BASE - 1, 0, id) << '\n';
ll val = queryMn(1, 0, BASE - 1, id, id) - queryMn(1, 0, BASE - 1, 0, id);
// cerr << id << ' ' << x << ' ' << val << '\n';
if(val < x){
ans[id] = 0;
continue;
}
val = (ll)-val + queryMx(1, 0, BASE - 1, id, id) + x;
int wsk = find(1, 0, BASE - 1, val);
ans[id] = C[wsk];
}
}
for(int i = 1; i <= q; i++){
if(xd67[i] == 3){
cout << ans[i] << '\n';
}
}
return 0;
}
| # | 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... |