답안 #555094

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
555094 2022-04-30T07:15:33 Z myungwoo Meteors (POI11_met) C++17
100 / 100
1713 ms 62460 KB
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
vector<int> sect[300001];
vector<vector<int> > cp;
ull goal[300001];
struct Day{
    int l,r; ull cnt;
    Day(){} Day(int l, int r, ull cnt):l(l),r(r),cnt(cnt){}
};
struct Fenwick{
    int s,e;
    vector<ull> tree, tadd;
    Fenwick(){} Fenwick(int n):s(1),e(n),tree(n+1,0ULL){}
    void clear() { tree.clear(); tree.resize(e+1,0ULL); }
    void rupdate(int left, int right, ull by) {
        inupdate(left, by);
        inupdate(right+1, -by);
    }
    void inupdate(int at, ull by) {
        for(int i=at; i<=e && i; i+=i&-i) tree[i]+=by;
    }
    ull query(int at) {
        ull ans=0ULL;
        for(int i=at; i>=1; i&=(i-1)) ans+=tree[i];
        return ans;
    }
};

vector<Day> day(1);
int l[300001], r[300001];
int main() {
    int n,m;
    assert(2 == scanf("%d%d",&n,&m) && 1 <= n && n <= 300000 && 1 <= m && m <= 300000);
    for(int i=1; i<=m; i++) {
        int x;
		assert(1 == scanf("%d",&x) && 1 <= x && x <= n);
        sect[x].push_back(i);
    }
    Fenwick fen(m);
	constexpr int MAX = 1e9;
    for(int i=1; i<=n; i++) {
        assert(1 == scanf("%llu",&goal[i]) && 1 <= goal[i] && goal[i] <= MAX);
    }
    int q;
	assert(1 == scanf("%d",&q) && 1 <= q && q <= 300000);
    for(int i=1; i<=q; i++) {
        int l,r; ull cnt;
        assert(3 == scanf("%d%d%llu",&l,&r,&cnt) && 1 <= l && l <= m && 1 <= r && r <= m && 1 <= cnt && cnt <= MAX);
        day.push_back(Day(l,r,cnt));
    }
    cp.resize(q+1, vector<int>());
    for(int i=1; i<=n; i++) l[i]=0, r[i]=q+1;
    while(true) {
        bool good=false;
        for(int i=1; i<=n; i++) {
            if(l[i]+1<r[i]) {
                cp[(l[i]+r[i])>>1].push_back(i);
                good=true;
            }
        }
        if(!good) break;

        int pi=1;
        for(int i=1; i<=q; i++) {
            //bring meteor shower!!
            if(!cp[i].size()) continue;
            for(int j=pi; j<=i; pi=++j) {
                if(day[j].l<=day[j].r) {
                    fen.rupdate(day[j].l,day[j].r,day[j].cnt);
                } else {
                    fen.rupdate(1,day[j].r,day[j].cnt);
                    fen.rupdate(day[j].l,m,day[j].cnt);
                }
            }

            for(int nara: cp[i]) {
                ull sum=0ULL;
                for(int k: sect[nara]) sum+=fen.query(k);
                int mid=(l[nara]+r[nara])>>1;
                if(sum>=goal[nara]) r[nara]=mid;
                else l[nara]=mid;
            }
            cp[i].clear();
        }
        fen.clear();
    }

    for(int i=1; i<=n; i++) {
        if(r[i]!=q+1) printf("%d\n", r[i]);
        else puts("NIE");
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 6 ms 7432 KB Output is correct
3 Correct 5 ms 7508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 6 ms 7380 KB Output is correct
3 Correct 6 ms 7504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 10904 KB Output is correct
2 Correct 103 ms 12976 KB Output is correct
3 Correct 102 ms 12488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 11916 KB Output is correct
2 Correct 91 ms 11968 KB Output is correct
3 Correct 100 ms 13052 KB Output is correct
4 Correct 33 ms 10156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 11328 KB Output is correct
2 Correct 89 ms 13540 KB Output is correct
3 Correct 30 ms 9836 KB Output is correct
4 Correct 91 ms 12868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 10492 KB Output is correct
2 Correct 95 ms 12040 KB Output is correct
3 Correct 71 ms 10816 KB Output is correct
4 Correct 112 ms 14244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 890 ms 35796 KB Output is correct
2 Correct 236 ms 23060 KB Output is correct
3 Correct 171 ms 19012 KB Output is correct
4 Correct 1540 ms 56900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 889 ms 34444 KB Output is correct
2 Correct 546 ms 23152 KB Output is correct
3 Correct 86 ms 16848 KB Output is correct
4 Correct 1713 ms 62460 KB Output is correct