Submission #799341

# Submission time Handle Problem Language Result Execution time Memory
799341 2023-07-31T12:56:07 Z dreamoon Meteors (POI11_met) C++14
74 / 100
606 ms 65536 KB
#include <iostream>
#include <vector>
#include <algorithm>
#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];
ll need[MAX],pre[MAX];
vector <int> sta[MAX]; // stations of every type
vector <Query> allQ;
vector <int> allT;
int a, b, c;
 
void solve(int le, int ri, vector <int> & type){ // type: station types and how much is needed, pos = le
    //cout << le << " " << ri << " " << SZ(type) << "\n";
    if (type.empty()) return;
    vector <pii> loc; // considered locations and dif
    vector <int> tCopy; // copy of type
    for (int t : type){
        pre[t] = need[t];
        for (int s : sta[t])
            loc.push_back({s, 0});
        tCopy.push_back(t);
    }
    sort(loc.begin(), loc.end());
    if (loc.empty()) return;
    
    int mid = le + (ri-le+2)/2;
    for (int i = le; i < mid; i++){ // set up prefix difference
        Query q = allQ[i];
        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(), arr[l.ind]);
        need[*it] -= sum;
        //cout << sum << " ";
    }
    
    if (le == ri){ // this is the final step
        for (int t : tCopy){
            if (need[t] <= 0) ans[t] = le+1;
        }
        return;
    }
    
    vector <int> typeA, typeB;
    for (int i = 0; i < SZ(type); i++){
        if (need[type[i]] <= 0) {
            need[type[i]] = pre[type[i]];
            typeA.push_back(type[i]);
        }
        else typeB.push_back(type[i]);
    }
    solve(le, mid-1, typeA);
    solve(mid, ri, typeB);
}
 
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 >> need[i];
        allT.push_back(i);
    }
    cin >> queNum;
    for (int i = 0; i < queNum; i++){
        cin >> a >> b >> c;
        allQ.push_back({a, b, c});
    }
    solve(0, queNum-1, allT);
    for (int i = 1; i <= typeNum; i++){
        if (ans[i] == 0) cout << "NIE\n";
        else cout << ans[i] << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7508 KB Output is correct
2 Correct 5 ms 7648 KB Output is correct
3 Correct 5 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7636 KB Output is correct
2 Correct 5 ms 7616 KB Output is correct
3 Correct 5 ms 7636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 19260 KB Output is correct
2 Correct 165 ms 28004 KB Output is correct
3 Correct 133 ms 12760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 12572 KB Output is correct
2 Correct 102 ms 12576 KB Output is correct
3 Correct 149 ms 21892 KB Output is correct
4 Correct 50 ms 16724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 14376 KB Output is correct
2 Correct 78 ms 22836 KB Output is correct
3 Correct 21 ms 8784 KB Output is correct
4 Correct 102 ms 13772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 18428 KB Output is correct
2 Correct 110 ms 18988 KB Output is correct
3 Correct 62 ms 13312 KB Output is correct
4 Correct 116 ms 16908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 606 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 598 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -