이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// vaziat meshki-ghermeze !
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
const ll Mod = 1000000007LL;
const int N = 25e4 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;
typedef pll pii;
pii seg[N << 2]; // sum ans
pii nl = {0, 0};
pii Merge(pii &A, pii &B){
return {A.F + B.F, min(A.S, A.F + B.S)};
}
void Apply(int id, pii X){
seg[id] = Merge(seg[id], X);
}
void Shift(int id){
Apply(id << 1, seg[id]);
Apply(id << 1 | 1, seg[id]);
seg[id] = nl;
}
void Add(int id, int l, int r, pii X, int L, int R){
if(r <= L || R <= l) return ;
if(l <= L && R <= r){
Apply(id, X);
return ;
}
int mid = (L + R) >> 1;
Shift(id);
Add(id << 1, l, r, X, L, mid);
Add(id<<1|1, l, r, X, mid, R);
}
pll Get(int id, int idx, int L, int R){
if(L + 1 == R) return seg[id];
int mid = (L + R) >> 1;
Shift(id);
if(idx < mid)
return Get(id << 1, idx, L, mid);
return Get(id << 1 | 1, idx, mid, R);
}
ll fen[N];
void Add(int idx, ll x){
for(; idx < N; idx += idx & (-idx))
fen[idx] += x;
}
ll Get(int idx){
ll res = 0;
for(; idx; idx -= idx & (-idx))
res += fen[idx];
return res;
}
int t[N];
ll a[N], b[N], c[N], d[N], ps[N];
int lf[N], rt[N];
vector<int> V[N];
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m, q;
cin >> n >> m >> q;
for(int i = 1; i <= q; i++){
cin >> t[i];
if(t[i] == 1)
cin >> a[i] >> b[i] >> c[i] >> d[i];
if(t[i] == 2){
cin >> a[i] >> b[i] >> c[i];
Add(a[i], c[i]);
Add(b[i] + 1, -c[i]);
}
if(t[i] == 3){
cin >> a[i] >> b[i];
lf[i] = m == 1 ? i - 1 : 0;
rt[i] = i + 1;
ps[i] = Get(a[i]);
}
}
for(int _ = 0; _ < 20; _++){
// debug(_);
for(int i = 1; i <= q; i++) V[i].clear();
memset(fen, 0, sizeof fen);
fill(seg, seg + (N << 2), nl);
int mid;
int fl = 0;
for(int i = 1; i <= q; i++){
if(t[i] == 3 && lf[i] + 1 < rt[i]){
// if(_>18) debug(_);
mid = (lf[i] + rt[i]) >> 1;
// debug(mid);
V[mid].pb(i);
fl = 1;
}
}
if(!fl) break;
for(int i = 1; i <= q; i++){
// debug(i);
if(t[i] == 1){
Add(1, a[i], b[i] + 1, {d[i], 0}, 1, n + 1);
} else if(t[i] == 2){
Add(1, a[i], b[i] + 1, {-c[i], -c[i]}, 1, n + 1);
Add(a[i], c[i]);
Add(b[i] + 1, -c[i]);
}
for(int q_id : V[i]){
pll res = Get(1, a[q_id], 1, n + 1);
ll nw = res.F - res.S;
ll dec = (ps[q_id] - Get(a[q_id]));
nw -= dec;
if(nw >= b[q_id])
rt[q_id] = i;
else
lf[q_id] = i;
}
}
}
for(int i = 1; i <= q; i++){
if(t[i] != 3) continue;
if(rt[i] == i + 1) cout << "0\n";
else
cout << (m == 1 ? 1 : c[rt[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... |