이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
struct P {
int l, r, a;
};
struct C{
int l, r;
};
int n, m, p[300003], q;
P predict[300003];
vector<int> own[300003];
C cur[300003];
int fenwick[600003];
void update(int idx, int val) {
while(idx<=2*m) {
fenwick[idx] += val;
idx += (idx & -idx);
}
}
int query(int idx) {
int ret = 0;
while(idx>0) {
ret += fenwick[idx];
idx -= (idx & -idx);
}
return ret;
}
void makefenwick(int time) {
for(int i=0;i<=m;i++) fenwick[i] = 0;
for(int i=1;i<=time;i++) {
update(predict[i].l, predict[i].a);
update(predict[i].r+1, -predict[i].a);
if(predict[i].r<predict[i].l) {
update(1, predict[i].a);
}
}
}
vector<int> mid[300003];
queue<int> qu;
bool inq[300003];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
for(int i=1;i<=m;i++) {
int o;
cin>>o;
own[o].push_back(i);
}
for(int i=1;i<=n;i++) {
cin>>p[i];
}
cin>>q;
for(int i=1;i<=q;i++) {
cin>>predict[i].l>>predict[i].r>>predict[i].a;
}
for(int i=1;i<=n;i++) {
cur[i] = {1, q+1};
mid[(2+q)/2].push_back(i);
}
qu.push((2+q)/2);
inq[(2+q)/2] = 1;
while(!qu.empty()) {
int md = qu.front();
qu.pop();
inq[md] = 0;
makefenwick(md);
for(int state:mid[md]) {
int ct = 0;
for(int station:own[state]) {
ct += query(station);
}
if(ct<p[state]) {
cur[state].l = md+1;
} else {
cur[state].r = md;
}
if(cur[state].l<cur[state].r) {
mid[(cur[state].l+cur[state].r)/2].push_back(state);
if(!inq[(cur[state].l+cur[state].r)/2]) {
qu.push((cur[state].l+cur[state].r)/2);
inq[(cur[state].l+cur[state].r)/2] = 1;
}
}
}
mid[md].clear();
}
for(int i=1;i<=n;i++) {
if(cur[i].l==q+1) cout<<"NIE\n";
else cout<<cur[i].l<<'\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... |