답안 #347649

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
347649 2021-01-13T09:52:43 Z saral Meteors (POI11_met) C++14
0 / 100
6000 ms 26024 KB
#include <bits/stdc++.h>

using namespace std;
#define lli long long int
const int N = 300100;
int t, n, m;
vector<int>states[N], pos, v;
lli tour[N*6], ness[N], OFF, sol[N], a, Q;
pair<pair<lli, lli>, lli> q[N];

void update (int l, int r, int x, int y, int node, lli value) {
    if (x <= l && r <= y) {
        tour[node]+=value;
        return;
    }
    if (r < x || l > y) return;
    int mid = (l+r)/2;
    update (l, mid, x, y, node*2, value);
    update (mid+1, r, x, y, node*2+1, value);
return;
}

lli get (int x) {
    lli rez=0;
    x = x+OFF-1;
    rez += tour[x];
    x/=2;
    while (x) {
        rez+=tour[x];
        x/=2;
    }
    return rez;
}

void f (int l, int r, vector<int> pos) {
    /*cout << l << " " << r << endl;
    for(int i = 0; i < pos.size(); i++){
        cout << pos[i] << " ";
    }
    cout<< endl;
    system("pause");*/

    int lb, rb;
    lli val;
    if (l==r) {
        for (int i = 0; i < pos.size(); i++) {
            sol[pos[i]]=l;
        }
        return;
    }
    int mid = (l+r)/2;
    vector<int>left;
    vector<int>right;

    for (int i = 1; i <= mid; i++) {
        lb = q[i].first.first, rb = q[i].first.second, val = q[i].second;
        if (lb <= rb) {
            update (1, OFF, lb, rb, 1, val);
        }
        else {
            update (1, OFF, lb, m, 1, val);
            update (1, OFF, 1, rb, 1, val);
        }
    }



    for (int i = 0; i < pos.size(); i++) {
        lli zbr = 0;
        for (int j = 0; j < states[pos[i]].size(); j++) {
            zbr += get (states[pos[i]][j]);
        }
        if (zbr >= ness[pos[i]]) {
            left.push_back(pos[i]);
        }
        else right.push_back(pos[i]);
        //cout << pos[i] << " " << zbr << endl;
    }
    //cout << endl;



    f (mid+1, r, right);

    for (int i = 1; i <= mid; i++) {
        lb = q[i].first.first, rb = q[i].first.second, val = q[i].second;
        if (lb <= rb) {
            update (1, OFF, lb, rb, 1, -val);
        }
        else {
            update (1, OFF, lb, m, 1, -val);
            update (1, OFF, 1, rb, 1, -val);
        }
    }

    f (l, mid, left);
return;
}

void solve () {
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        cin >> a;
        states[a].push_back(i);
    }
    OFF=1;
    while (OFF < m)  OFF*=2;
    for (int i = 1; i <= n; i++) cin >> ness[i];
    cin >> Q;
    for (int i = 1; i <= Q; i++) cin >> q[i].first.first >> q[i].first.second >> q[i].second;
    for (int i = 1; i <= n; i++) v.push_back(i);
    f (1, Q+5, v);
    for (int i = 1; i <= n; i++) {
        if (sol[i] > Q) cout << "NIE\n";
        else cout << sol[i] << "\n";
    }
return;
}

int main () {
	solve();

return 0;
}

Compilation message

met.cpp: In function 'void f(int, int, std::vector<int>)':
met.cpp:46:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for (int i = 0; i < pos.size(); i++) {
      |                         ~~^~~~~~~~~~~~
met.cpp:68:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for (int i = 0; i < pos.size(); i++) {
      |                     ~~^~~~~~~~~~~~
met.cpp:70:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for (int j = 0; j < states[pos[i]].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 156 ms 7404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 182 ms 7532 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6063 ms 10476 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6032 ms 10092 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6087 ms 9964 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6083 ms 9708 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6080 ms 26024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6083 ms 25444 KB Time limit exceeded
2 Halted 0 ms 0 KB -