Submission #788664

# Submission time Handle Problem Language Result Execution time Memory
788664 2023-07-20T13:05:06 Z Dawnlight Meteors (POI11_met) C++14
0 / 100
251 ms 65536 KB
#include <bits/stdc++.h>
#define ll long long
#define SZ(X) (int)(X.size())
#define MAX 300005
#define pii pair <int,ll>
#define ind first
#define val second
#define INF (ll)(1e18)
using namespace std;

struct Query{
    int le, ri, amo;
};

int typeNum, len, queNum;
int arr[MAX];
int ans[MAX];
vector <int> sta[MAX]; // stations of every type
vector <Query> allQ;
vector <pii> allT;
int a, b, c;

void solve(vector <Query> & que, vector <pii> & type, int pos){ // type: station types and how much is needed, pos = le
    //cout << SZ(que) << " " << SZ(type) << " " << pos << "\n";
    vector <pii> loc; // considered locations and dif
    vector <pii> tCopy; // copy of type
    for (pii t : type){
        for (int s : sta[t.ind])
            loc.push_back({s, 0});
        tCopy.push_back(t);
    }
    sort(loc.begin(), loc.end());
    
    vector <Query> queA, queB; // separate que into first and second half
    for (int i = 0; i < SZ(que); i++){
        if (i < (SZ(que)+1)/2) queA.push_back(que[i]);
        else queB.push_back(que[i]);
    }
    for (Query q : queA){ // set up prefix difference
        int add = q.le, sub = q.ri;
        if (q.le > q.ri) { // ring-shaped array
            loc[0].val += q.amo;
        }
        auto it = lower_bound(loc.begin(), loc.end(), make_pair(add, -INF));
        if (it != loc.end()) it->val += q.amo;
        it = lower_bound(loc.begin(), loc.end(), make_pair(sub+1, -INF));
        if (it != loc.end()) it->val -= q.amo;
    }
    ll sum = 0;
    for (pii l : loc){ // use prefix difference to calculate how much more we need for each type
        sum += l.val;
        auto it = lower_bound(tCopy.begin(), tCopy.end(), make_pair(arr[l.ind], -INF));
        it->val -= sum;
        //cout << sum << " ";
    }
    
    if (queB.empty()){ // this is the final step
        for (pii t : tCopy){
            if (t.val <= 0) ans[t.ind] = pos;
            else ans[t.ind] = -1;
        }
        return;
    }
    
    vector <pii> typeA, typeB;
    for (int i = 0; i < SZ(type); i++){
        if (tCopy[i].val <= 0) typeA.push_back(type[i]);
        else typeB.push_back(tCopy[i]);
    }
    solve(queA, typeA, pos);
    solve(queB, typeB, pos+SZ(queA));
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> typeNum >> len;
    for (int i = 1; i <= len; i++) {
        cin >> arr[i];
        sta[arr[i]].push_back(i);
    }
    for (int i = 1; i <= typeNum; i++){
        cin >> a;
        allT.push_back({i, a});
    }
    cin >> queNum;
    for (int i = 1; i <= queNum; i++){
        cin >> a >> b >> c;
        allQ.push_back({a, b, c});
    }
    solve(allQ, allT, 1);
    for (int i = 1; i <= typeNum; i++){
        if (ans[i] == -1) cout << "NIE\n";
        else cout << ans[i] << "\n";
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 14972 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 15484 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 76 ms 32156 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 43 ms 26296 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 69 ms 16792 KB Output is correct
2 Runtime error 39 ms 27708 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 81 ms 37204 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 251 ms 65536 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 247 ms 65536 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -