이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define f first
#define s second
using namespace std;
const int mxn=3e5+5;
const int inf=1e9;
int n,m,q;
struct segtree {
ll removed[4 * mxn] = {};
ll added[4 * mxn] = {};
pii tree[4 * mxn];
void init(int n) {
for(int i = 0; i < 4 * mxn; i++) tree[i] = {0,0};
}
pii merge(pii a, pii b) {
return { b.f + max(0ll, a.f - b.s), a.s + max(0ll,b.s - a.f) };
}
void propogate(int node) {
int left = node << 1;
int right = left | 1;
removed[left] += min(tree[node].f,tree[left].s);
removed[right] += min(tree[node].f,tree[right].s);
tree[left] = merge(tree[node], tree[left]);
tree[right] = merge(tree[node], tree[right]);
removed[left] += removed[node];
removed[right] += removed[node];
removed[node] = 0;
added[left] += added[node];
added[right] += added[node];
added[node] = 0;
tree[node] = {0,0};
}
void update(int node,int b,int e,int l,int r, pii v) {
if(e < l || b > r) return;
if(b >= l && e <= r) {
removed[node] += min(v.first, tree[node].s);
added[node] += v.s;
tree[node] = merge(v, tree[node]);
// cout<<"After update ("<<b<<" "<<e<<") ("<<v.f<<" - "<<v.s<<") ("<<tree[node].f<<" "<<tree[node].s<<") "<<removed[node]<<endl;
return;
}
propogate(node);
int mid = b + e >>1;
int left = node << 1;
int right = left | 1;
update(left, b, mid, l, r, v);
update(right, mid + 1, e, l, r, v);
}
int query(int node,int b,int e,int p) {
if(b == e) return node;
int mid = b + e >> 1;
int left = node << 1;
int right = left | 1;
propogate(node);
if(p <= mid) return query(left,b,mid,p);
return query(right, mid + 1,e,p);
}
} st;
int type[mxn],l[mxn],r[mxn],c[mxn];
ll k[mxn];
ll a[mxn],b[mxn];
int res[mxn];
ll pos[mxn];
int main() {
memset(res,-1,sizeof res);
cin >> n >> m >> q;
st.init(n);
for(int i = 1; i <= q; i++) {
scanf("%d",&type[i]);
if(type[i] == 1) {
scanf("%d%d%d %lld",&l[i],&r[i],&c[i],&k[i]);
st.update(1,1,n,l[i],r[i],{0,k[i]});
} else if(type[i] == 2) {
scanf("%d%d %lld",&l[i],&r[i],&k[i]);
st.update(1,1,n,l[i],r[i],{k[i],0});
} else {
scanf("%lld %lld",&a[i],&b[i]);
int node = st.query(1,1,n,a[i]);
if(st.tree[node].s >= b[i]) {
pos[i] = st.removed[node] + b[i];
}
else res[i] = 0;
}
}
for(int i = 1; i <= q; i++) {
if(type[i] != 3) continue;
if(res[i] == 0) {
printf("0\n");
continue;
}
ll sum = 0;
for(int j = 1; j < i; j++) {
if(type[j] == 1 && l[j] <= a[i] && a[i] <= r[j]) {
sum += k[j];
if(sum >= pos[i]) {
printf("%d\n",c[j]);
break;
}
}
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
foodcourt.cpp: In member function 'void segtree::update(int, int, int, int, int, std::pair<long long int, long long int>)':
foodcourt.cpp:63:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
63 | int mid = b + e >>1;
| ~~^~~
foodcourt.cpp: In member function 'int segtree::query(int, int, int, int)':
foodcourt.cpp:74:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
74 | int mid = b + e >> 1;
| ~~^~~
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:99:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
99 | scanf("%d",&type[i]);
| ~~~~~^~~~~~~~~~~~~~~
foodcourt.cpp:102:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
102 | scanf("%d%d%d %lld",&l[i],&r[i],&c[i],&k[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:105:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
105 | scanf("%d%d %lld",&l[i],&r[i],&k[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:109:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
109 | scanf("%lld %lld",&a[i],&b[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |