답안 #799169

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
799169 2023-07-31T10:26:58 Z dreamoon Meteors (POI11_met) C++14
0 / 100
615 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];
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){
        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) 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";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 57 ms 22764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 79 ms 17240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 60 ms 13812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 104 ms 22524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 612 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 615 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -