답안 #1012990

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1012990 2024-07-03T04:21:34 Z octane Meteors (POI11_met) C++17
74 / 100
2722 ms 57492 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
struct qu{
    int l, r;
    ll a;
    qu(){}
    qu(int l, int r, ll a): l(l), r(r), a(a){}
};
typedef pair<int, int> pi;
typedef pair<pi, vector<int>> pii;

int n, k, q, x;
ll goal[300005];
qu qus[300005];
ll tree[1200005];
vector<int> num[300005];
int res[300005];
vector<pii> vec[50];

void init(int node, int s, int e){
    tree[node] = 0;
    if(s==e) return;
    int m = (s+e)>>1;
    init(node<<1, s, m);
    init(node<<1|1, m+1, e);
}

void update(int node, int s, int e, int l, ll v){
    if(e<l||l<s) return;
    if(s==e){
        tree[node] += v;
        return;
    }
    int m = (s+e)>>1;
    update(node<<1, s, m, l, v);
    update(node<<1|1, m+1, e, l, v);
    tree[node] = tree[node<<1]+tree[node<<1|1];
}

ll query(int node, int s, int e, int l, int r){
    if(e<l||r<s) return 0;
    if(l<=s&&e<=r) return tree[node];
    int m = (s+e)>>1;
    return query(node<<1, s, m, l, r)+query(node<<1|1, m+1, e, l, r);
}

int main(){
    scanf("%d %d", &n, &k);
    for(int i=1;i<=k;i++){
        scanf("%d", &x);
        num[x].push_back(i);
    }
    for(int i=1;i<=n;i++) scanf("%d", &goal[i]);
    scanf("%d", &q);
    vector<int> emp;
    for(int i=1;i<=n;i++) emp.push_back(i);
    vec[0].push_back(pii(pi(0, q-1), emp));
    for(int i=0;i<q;i++) scanf("%d %d %d", &qus[i].l, &qus[i].r, &qus[i].a);
    int idx = 0;
    while(!vec[idx].empty()){
        init(1, 1, k+1);
        int prv = 0;
        for(auto p: vec[idx]){
            int s = p.first.first;
            int e = p.first.second;
            int m = (s+e)>>1;
            vector<int> v = p.second;
            if(s==e){
                for(int i=prv;i<=s;i++){
                    if(qus[i].l<=qus[i].r){
                        update(1, 1, k+1, qus[i].l, qus[i].a);
                        update(1, 1, k+1, qus[i].r+1, -qus[i].a);
                    }
                    else{
                        update(1, 1, k+1, qus[i].l, qus[i].a);
                        update(1, 1, k+1, k+1, -qus[i].a);
                        update(1, 1, k+1, 1, qus[i].a);
                        update(1, 1, k+1, qus[i].r+1, -qus[i].a);
                    }
                }
                for(auto u: v){
                    ll sm = 0;
                    for(auto w: num[u]) sm += query(1, 1, k+1, 1, w);
                    if(sm>=goal[u]) res[u] = s;
                    else res[u] = -1;
                }
                prv = e+1;
                continue;
            }
            vector<int> vec1;
            vector<int> vec2;
            for(int i=prv;i<=m;i++){
                if(qus[i].l<=qus[i].r){
                    update(1, 1, k+1, qus[i].l, qus[i].a);
                    update(1, 1, k+1, qus[i].r+1, -qus[i].a);
                }
                else{
                    update(1, 1, k+1, qus[i].l, qus[i].a);
                    update(1, 1, k+1, k+1, -qus[i].a);
                    update(1, 1, k+1, 1, qus[i].a);
                    update(1, 1, k+1, qus[i].r+1, -qus[i].a);
                }
            }
            for(auto u: v){
                ll sm = 0;
                for(auto w: num[u]) sm += query(1, 1, k+1, 1, w);
                if(sm>=goal[u]) vec1.push_back(u);
                else vec2.push_back(u);
            }
            for(int i=m+1;i<=e;i++){
                if(qus[i].l<=qus[i].r){
                    update(1, 1, k+1, qus[i].l, qus[i].a);
                    update(1, 1, k+1, qus[i].r+1, -qus[i].a);
                }
                else{
                    update(1, 1, k+1, qus[i].l, qus[i].a);
                    update(1, 1, k+1, k+1, -qus[i].a);
                    update(1, 1, k+1, 1, qus[i].a);
                    update(1, 1, k+1, qus[i].r+1, -qus[i].a);
                }
            }
            prv = e+1;
            vec[idx+1].push_back(pii(pi(s, m), vec1));
            vec[idx+1].push_back(pii(pi(m+1, e), vec2));
        }
        idx++;
    }
    for(int i=1;i<=n;i++){
        if(res[i]==-1) printf("NIE\n");
        else printf("%d\n", res[i]+1);
    }
}

Compilation message

met.cpp: In function 'int main()':
met.cpp:59:35: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'll*' {aka 'long long int*'} [-Wformat=]
   59 |     for(int i=1;i<=n;i++) scanf("%d", &goal[i]);
      |                                  ~^   ~~~~~~~~
      |                                   |   |
      |                                   |   ll* {aka long long int*}
      |                                   int*
      |                                  %lld
met.cpp:64:40: warning: format '%d' expects argument of type 'int*', but argument 4 has type 'll*' {aka 'long long int*'} [-Wformat=]
   64 |     for(int i=0;i<q;i++) scanf("%d %d %d", &qus[i].l, &qus[i].r, &qus[i].a);
      |                                       ~^                         ~~~~~~~~~
      |                                        |                         |
      |                                        int*                      ll* {aka long long int*}
      |                                       %lld
met.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
met.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
met.cpp:59:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |     for(int i=1;i<=n;i++) scanf("%d", &goal[i]);
      |                           ~~~~~^~~~~~~~~~~~~~~~
met.cpp:60:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
met.cpp:64:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     for(int i=0;i<q;i++) scanf("%d %d %d", &qus[i].l, &qus[i].r, &qus[i].a);
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10584 KB Output is correct
2 Correct 5 ms 12632 KB Output is correct
3 Correct 5 ms 10840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10844 KB Output is correct
2 Correct 5 ms 12708 KB Output is correct
3 Correct 5 ms 12720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 235 ms 16388 KB Output is correct
2 Correct 339 ms 20420 KB Output is correct
3 Correct 300 ms 21344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 310 ms 18656 KB Output is correct
2 Correct 297 ms 18660 KB Output is correct
3 Correct 331 ms 19376 KB Output is correct
4 Correct 77 ms 14768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 169 ms 17048 KB Output is correct
2 Correct 241 ms 19952 KB Output is correct
3 Correct 118 ms 17220 KB Output is correct
4 Correct 292 ms 18992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 350 ms 16028 KB Output is correct
2 Correct 241 ms 17372 KB Output is correct
3 Correct 224 ms 17612 KB Output is correct
4 Correct 297 ms 23292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2722 ms 57492 KB Output is correct
2 Incorrect 1903 ms 46048 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2713 ms 55896 KB Output is correct
2 Incorrect 1162 ms 46072 KB Output isn't correct
3 Halted 0 ms 0 KB -