이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
const ll NMAX = 250002;
const int INF = 1e9;
const ll nrbits = 20;
const ll MOD = 998244353;
vector <int> events[NMAX];
vector <int> queries[NMAX];
int t[NMAX];
pii q[NMAX];
int qq;
int sol[NMAX];
struct Node{
ll total, maxSuff;
}aint[NMAX * 4];
Node combine(Node a, Node b){
Node sol = {a.total + b.total, max({b.maxSuff, a.maxSuff + b.total})};
/// Am nevoie de cel mai mare sufix care se TERMINA IN MINE
return sol;
}
void update(int node, int st, int dr, int a, ll b){
if(st == dr){
aint[node] = {b, max(0LL, b)};
return;
}
int mid = (st + dr) / 2;
if(a <= mid)
update(node * 2, st, mid, a, b);
else update(node * 2 + 1, mid + 1, dr, a, b);
aint[node] = combine(aint[node * 2], aint[node * 2 + 1]);
}
Node maxSuff(int node, int st, int dr, int a, int b){
if(a <= st && dr <= b){
return aint[node];
}
int mid = (st + dr) / 2;
Node sol = {0, 0};
if(a <= mid) sol = combine(sol, maxSuff(node * 2, st, mid, a, b));
if(b > mid) sol = combine(sol, maxSuff(node * 2 + 1, mid + 1, dr, a, b));
return sol;
}
pii aib[NMAX];
void baga(pii x, ll val){
aib[x.first].second = x.second;
for(; x.first <= qq; x.first += x.first&(-x.first))
aib[x.first].first += val;
}
ll query(int x){
ll sol = 0;
for(; x; x -= x&(-x))
sol += aib[x].first;
return sol;
}
int Search(ll x){
int r = 0, pas = (1 << nrbits);
ll s = 0;
while(pas){
if(r + pas <= qq && (s + aib[r + pas].first) < x){
s += aib[r + pas].first;
r += pas;
}
pas /= 2;
}
r++;
return aib[r].second;
}
signed main() {
#ifdef HOME
ifstream cin(".in");
ofstream cout(".out");
#endif // HOME
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, i;
for(i = 0; i < NMAX * 4; i++) aint[i] = {0, 0};
cin >> n >> m >> qq;
for(i = 1; i <= qq; i++){
cin >> t[i];
if(t[i] == 3){
cin >> q[i].first >> q[i].second;
queries[q[i].first].push_back(i);
}else if(t[i] == 2){
int l, r;
cin >> l >> r >> q[i].first;
events[l].push_back(i);
events[r + 1].push_back(-i);
}else{
int l, r;
cin >> l >> r >> q[i].second >> q[i].first;
events[l].push_back(i);
events[r + 1].push_back(-i);
}
}
for(i = 1; i <= n; i++){
for(auto x : events[i]){
if(x < 0){
if(t[-x] == 1){
baga({-x, q[-x].second}, -q[-x].first);
}
update(1, 1, qq, -x, 0);
}else{
if(t[x] == 1){
baga({x, q[x].second}, q[x].first);
update(1, 1, qq, x, q[x].first);
}else{
update(1, 1, qq, x, -q[x].first);
}
}
}
for(auto x : queries[i]){
ll untilNow = query(x);
ll currentSize = maxSuff(1, 1, qq, 1, x).maxSuff;
ll b = q[x].second;
if(b <= currentSize)
sol[x] = Search(untilNow - currentSize + b);
else
sol[x] = 0;
}
}
for(i = 1; i <= qq; i++){
if(t[i] == 3) cout << sol[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... |