#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;
const int tree_siz = 1024*512-1;
ll min_[tree_siz+1];
ll oper[tree_siz+1];
void push(int v)
{
min_[v*2+1] += oper[v];
min_[v*2] += oper[v];
oper[v*2+1] += oper[v];
oper[v*2] += oper[v];
oper[v] = 0;
}
void add_seg(int akt, int p1, int p2, int s1, int s2, ll x)
{
if(p2 < s1 || p1 > s2) return;
if(p1 >= s1 && p2 <= s2)
{
min_[akt] += x;
oper[akt] += x;
return;
}
push(akt);
add_seg(akt*2,p1,(p1+p2)/2,s1,s2,x);
add_seg(akt*2+1,(p1+p2)/2+1,p2,s1,s2,x);
min_[akt] = min(min_[akt*2],min_[akt*2+1]);
}
ll get_min(int akt, int p1, int p2, int s1, int s2)
{
if(p2 < s1 || p1 > s2) return 1e18;
if(p1 >= s1 && p2 <= s2) return min_[akt];
push(akt);
return min(get_min(akt*2,p1,(p1+p2)/2,s1,s2),get_min(akt*2+1,(p1+p2)/2+1,p2,s1,s2));
}
ll max_[tree_siz+1];
ll oper2[tree_siz+1];
void push2(int v)
{
max_[v*2+1] += oper2[v];
max_[v*2] += oper2[v];
oper2[v*2+1] += oper2[v];
oper2[v*2] += oper2[v];
oper2[v] = 0;
}
void add_seg2(int akt, int p1, int p2, int s1, int s2, ll x)
{
if(p2 < s1 || p1 > s2) return;
if(p1 >= s1 && p2 <= s2)
{
max_[akt] += x;
oper2[akt] += x;
return;
}
push2(akt);
add_seg2(akt*2,p1,(p1+p2)/2,s1,s2,x);
add_seg2(akt*2+1,(p1+p2)/2+1,p2,s1,s2,x);
max_[akt] = max(max_[akt*2],max_[akt*2+1]);
}
ll get_max(int akt, int p1, int p2, int s1, int s2)
{
if(p2 < s1 || p1 > s2) return 0;
if(p1 >= s1 && p2 <= s2) return max_[akt];
push2(akt);
return max(get_max(akt*2,p1,(p1+p2)/2,s1,s2),get_max(akt*2+1,(p1+p2)/2+1,p2,s1,s2));
}
int find_first(int v, int p1, int p2, ll val)
{
if(p1 == p2) return v-(tree_siz/2+1);
push2(v);
if(max_[v*2] < val) return find_first(v*2+1,(p1+p2)/2+1,p2,val);
return find_first(v*2,p1,(p1+p2)/2,val);
}
struct operS
{
ll val;
int ind,c,type;
};
vector<operS> operations[250003];
operS opers[250003];
vector<pll> queries[250003];
int query_ans[250003];
vi q_list;
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//random_start();
int n,m,q;
cin >> n >> m >> q;
rep2(qq,1,q)
{
int t;
cin >> t;
if(t == 1)
{
int l,r,c,k;
cin >> l >> r >> c >> k;
opers[qq] = {k,qq,c,1};
operations[l].pb(opers[qq]);
opers[qq].val *= -1;
operations[r+1].pb(opers[qq]);
opers[qq].val *= -1;
}
if(t == 2)
{
int l,r,k;
cin >> l >> r >> k;
opers[qq] = {-k,qq,-1,-1};
operations[l].pb(opers[qq]);
opers[qq].val *= -1;
operations[r+1].pb(opers[qq]);
opers[qq].val *= -1;
}
if(t == 3)
{
int v;
ll val;
cin >> v >> val;
queries[v].pb({val,qq});
q_list.pb(qq);
}
}
rep2(i,1,n)
{
forall(it,operations[i])
{
add_seg(1,0,tree_siz/2,it.ind,q,it.val);
if(it.type == 1) add_seg2(1,0,tree_siz/2,it.ind,q,it.val);
}
forall(it,queries[i])
{
ll cur_val = get_min(1,0,tree_siz/2,it.ss,it.ss)-get_min(1,0,tree_siz/2,0,it.ss);
if(cur_val < it.ff) continue;
ll query_elm = get_max(1,0,tree_siz/2,it.ss,it.ss)-cur_val+it.ff;
query_ans[it.ss] = opers[find_first(1,0,tree_siz/2,query_elm)].c;
}
}
forall(it,q_list) cout << query_ans[it] << "\n";
}
| # | 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... |