답안 #491706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
491706 2021-12-03T22:39:35 Z faresbasbs Meteors (POI11_met) C++14
0 / 100
6000 ms 28360 KB
#include <bits/stdc++.h>
using namespace std;

struct p{
    int l1,r1,l2,r2,val;
};

const int sq = 300001;
int n,m,k,t,type[300001],val[300001];
vector<long long> segment;
pair<int,int> lst[300001];
vector<int> all[300001];
long long sum[300001];
bool done[300001];
p event[300001];

void upd(int a , int b , int v , int curr , int l , int r){
    if(b < l || a > r){
        return ;
    }
    if(a <= l && b >= r){
        segment[curr] += v;
        return ;
    }
    int mid = (l+r)/2;
    upd(a,b,v,2*curr,l,mid),upd(a,b,v,2*curr+1,mid+1,r);
}

long long getsum(int idx){
    idx += t-1;
    long long ret = 0;
    while(idx){
        ret += segment[idx];
        idx /= 2;
    }
    return ret;
}

long long num(int l , int r , int idx){
    return (upper_bound(all[idx].begin(),all[idx].end(),r)-all[idx].begin())-(lower_bound(all[idx].begin(),all[idx].end(),l)-all[idx].begin());
}

long long getval(int idx , int ev){
    long long numb = num(event[ev].l1,event[ev].r1,idx)+(event[ev].l2 == -1 ? 0ll : num(event[ev].l2,event[ev].r2,idx));
    return 1ll*event[ev].val*numb;
}

void check(int idx){
    for(int i = 1 ; i <= n ; i += 1){
        sum[i] = 0;
    }
    for(int i = 1 ; i <= m ; i += 1){
        if(done[type[i]]){
            continue;
        }
        sum[type[i]] += getsum(i);
    }
    for(int i = 1 ; i <= n ; i += 1){
        if(sum[i] >= val[i]){
            done[i] = 1;
        }
        if(done[i]){
            continue;
        }
        lst[i] = {sum[i],idx};
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);
    cin >> n >> m;
    t = pow(2,ceil(log2(m)));
    segment.resize(2*t,0);
    for(int i = 1 ; i <= m ; i += 1){
        cin >> type[i];
        all[type[i]].push_back(i);
    }
    for(int i = 1 ; i <= n ; i += 1){
        cin >> val[i];
        lst[i] = {0,0};
    }
    cin >> k;
    for(int i = 1 ; i <= k ; i += 1){
        int l,r,v;
        cin >> l >> r >> v;
        if(r >= l){
            event[i] = {l,r,-1,-1,v};
            upd(l,r,v,1,1,t);
        }else{
            event[i] = {l,m,1,r,v};
            upd(l,m,v,1,1,t),upd(1,r,v,1,1,t);
        }
        if(i%sq == 0){
            check(i);
        }
    }
    check(n);
    for(int i = 1 ; i <= n ; i += 1){
        pair<long long,long long> curr = lst[i];
        bool ok = 1;
        while(curr.first < val[i]){
            curr.second += 1;
            if(curr.second == m+1){
                ok = 0;
                break;
            }
            curr.first += getval(i,curr.second);
        }
        if(!ok){
            cout << "NIE\n";
        }else{
            cout << curr.second << '\n';
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 7372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Incorrect 9 ms 7472 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1129 ms 10008 KB Output is correct
2 Execution timed out 6053 ms 10896 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4580 ms 10340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1745 ms 10204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 9796 KB Output is correct
2 Incorrect 2155 ms 10372 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6068 ms 28360 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6056 ms 27884 KB Time limit exceeded
2 Halted 0 ms 0 KB -