답안 #108440

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
108440 2019-04-29T14:59:10 Z szawinis Examination (JOI19_examination) C++17
100 / 100
599 ms 31788 KB
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <bits/stdc++.h>
using namespace std;
#define long long long
const long MOD = 1e9+7, LINF = 1e18 + 1e16;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const int N = 1e5+1;

struct fenwick {
    vector<int> f;
    fenwick(int n) {
        f.resize(n + 10);
    }
    void update(int i) {
        assert(i >= 0);
        ++i;
        while(i < f.size()) ++f[i], i += i & -i;
    }
    int query(int i) {
        ++i;
        int ret = 0;
        while(i > 0) ret += f[i], i -= i & -i;
        return ret;
    }
};

struct info {
    int sum, x, y, tp, id;
    info(int sum, int x, int y, int tp, int id): sum(sum), x(x), y(y), tp(tp), id(id) {}
    bool operator<(const info& rhs) const {
        return make_tuple(sum, x, y, tp, id) < make_tuple(rhs.sum, rhs.x, rhs.y, rhs.tp, rhs.id);
    }
};

class Examination {

    int n, q, res[N];
    vector<int> ls[N], xs;
    vector<info> a;
    fenwick *f[N];

    void compress() {
        sort(xs.begin(), xs.end());
        xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
        for(int i = 0; i < n; i++) {
            a[i].x = lower_bound(xs.begin(), xs.end(), a[i].x) - xs.begin();
        }
    }

    void ins(int i, int v) {
        ++i;
        while(i <= xs.size()) ls[i].push_back(v), i += i & -i;
    }

    void build() {
        for(int i = 1; i <= xs.size(); i++) {
            sort(ls[i].begin(), ls[i].end());
            ls[i].resize(unique(ls[i].begin(), ls[i].end()) - ls[i].begin());
            f[i] = new fenwick(ls[i].size());
        }
    }

    void update(int i, int v) {
        assert(i >= 0);
        ++i;
        while(i <= xs.size()) {
            auto it = lower_bound(ls[i].begin(), ls[i].end(), v);
            assert(*it == v);
            f[i]->update(it - ls[i].begin());
            i += i & -i;
        }
    }

    int query(int i, int v) {
        ++i;
        int ret = 0;
        while(i > 0) {
            auto it = upper_bound(ls[i].begin(), ls[i].end(), v);
            ret += f[i]->query(it - ls[i].begin() - 1);
            i -= i & -i;
        }
        return ret;
    }

public:
    void solve(istream &cin, ostream &cout) {
        cin >> n >> q;
        for(int i = 0, x, y; i < n; i++) {
            cin >> x >> y;
            x *= -1, y *= -1;
            xs.push_back(x);
            a.emplace_back(x + y, x, y, 0, i);
        }
        compress();
        for(info tt: a) {
            if(tt.tp == 0) ins(tt.x, tt.y);
        }
        build();

        for(int i = 0, x, y, z; i < q; i++) {
            cin >> x >> y >> z;
            x *= -1, y *= -1, z *= -1;
            auto itx = upper_bound(xs.begin(), xs.end(), x);
            int posx = itx - xs.begin() - 1;
            a.emplace_back(z, posx, y, 1, i);
        }
        sort(a.begin(), a.end());
        for(info tt: a) {
            if(tt.tp == 0) update(tt.x ,tt.y);
            else res[tt.id] = query(tt.x, tt.y);
        }
        for(int i = 0; i < q; i++) {
            cout << res[i] << '\n';
        }
    }
};

class Solver {
public:
    void solve(std::istream& in, std::ostream& out) {
        Examination *obj = new Examination();
        obj->solve(in, out);
        delete obj;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    Solver solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}

Compilation message

examination.cpp: In member function 'void fenwick::update(int)':
examination.cpp:24:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(i < f.size()) ++f[i], i += i & -i;
               ~~^~~~~~~~~~
examination.cpp: In member function 'void Examination::ins(int, int)':
examination.cpp:59:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(i <= xs.size()) ls[i].push_back(v), i += i & -i;
               ~~^~~~~~~~~~~~
examination.cpp: In member function 'void Examination::build()':
examination.cpp:63:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 1; i <= xs.size(); i++) {
                        ~~^~~~~~~~~~~~
examination.cpp: In member function 'void Examination::update(int, int)':
examination.cpp:73:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(i <= xs.size()) {
               ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3840 KB Output is correct
2 Correct 5 ms 3840 KB Output is correct
3 Correct 5 ms 3840 KB Output is correct
4 Correct 7 ms 3840 KB Output is correct
5 Correct 7 ms 3840 KB Output is correct
6 Correct 6 ms 3840 KB Output is correct
7 Correct 13 ms 4736 KB Output is correct
8 Correct 12 ms 4736 KB Output is correct
9 Correct 13 ms 4736 KB Output is correct
10 Correct 14 ms 4608 KB Output is correct
11 Correct 13 ms 4224 KB Output is correct
12 Correct 9 ms 4224 KB Output is correct
13 Correct 14 ms 4736 KB Output is correct
14 Correct 14 ms 4736 KB Output is correct
15 Correct 14 ms 4736 KB Output is correct
16 Correct 8 ms 4224 KB Output is correct
17 Correct 10 ms 4608 KB Output is correct
18 Correct 9 ms 4224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 446 ms 24952 KB Output is correct
2 Correct 447 ms 25084 KB Output is correct
3 Correct 432 ms 24956 KB Output is correct
4 Correct 232 ms 22024 KB Output is correct
5 Correct 131 ms 12808 KB Output is correct
6 Correct 99 ms 11528 KB Output is correct
7 Correct 407 ms 24848 KB Output is correct
8 Correct 356 ms 24972 KB Output is correct
9 Correct 395 ms 24828 KB Output is correct
10 Correct 103 ms 11656 KB Output is correct
11 Correct 227 ms 21868 KB Output is correct
12 Correct 90 ms 11016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 446 ms 24952 KB Output is correct
2 Correct 447 ms 25084 KB Output is correct
3 Correct 432 ms 24956 KB Output is correct
4 Correct 232 ms 22024 KB Output is correct
5 Correct 131 ms 12808 KB Output is correct
6 Correct 99 ms 11528 KB Output is correct
7 Correct 407 ms 24848 KB Output is correct
8 Correct 356 ms 24972 KB Output is correct
9 Correct 395 ms 24828 KB Output is correct
10 Correct 103 ms 11656 KB Output is correct
11 Correct 227 ms 21868 KB Output is correct
12 Correct 90 ms 11016 KB Output is correct
13 Correct 533 ms 25484 KB Output is correct
14 Correct 495 ms 25516 KB Output is correct
15 Correct 418 ms 25088 KB Output is correct
16 Correct 280 ms 22448 KB Output is correct
17 Correct 156 ms 12924 KB Output is correct
18 Correct 97 ms 11652 KB Output is correct
19 Correct 493 ms 25488 KB Output is correct
20 Correct 554 ms 25368 KB Output is correct
21 Correct 582 ms 25344 KB Output is correct
22 Correct 99 ms 11656 KB Output is correct
23 Correct 243 ms 21756 KB Output is correct
24 Correct 86 ms 11144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3840 KB Output is correct
2 Correct 5 ms 3840 KB Output is correct
3 Correct 5 ms 3840 KB Output is correct
4 Correct 7 ms 3840 KB Output is correct
5 Correct 7 ms 3840 KB Output is correct
6 Correct 6 ms 3840 KB Output is correct
7 Correct 13 ms 4736 KB Output is correct
8 Correct 12 ms 4736 KB Output is correct
9 Correct 13 ms 4736 KB Output is correct
10 Correct 14 ms 4608 KB Output is correct
11 Correct 13 ms 4224 KB Output is correct
12 Correct 9 ms 4224 KB Output is correct
13 Correct 14 ms 4736 KB Output is correct
14 Correct 14 ms 4736 KB Output is correct
15 Correct 14 ms 4736 KB Output is correct
16 Correct 8 ms 4224 KB Output is correct
17 Correct 10 ms 4608 KB Output is correct
18 Correct 9 ms 4224 KB Output is correct
19 Correct 446 ms 24952 KB Output is correct
20 Correct 447 ms 25084 KB Output is correct
21 Correct 432 ms 24956 KB Output is correct
22 Correct 232 ms 22024 KB Output is correct
23 Correct 131 ms 12808 KB Output is correct
24 Correct 99 ms 11528 KB Output is correct
25 Correct 407 ms 24848 KB Output is correct
26 Correct 356 ms 24972 KB Output is correct
27 Correct 395 ms 24828 KB Output is correct
28 Correct 103 ms 11656 KB Output is correct
29 Correct 227 ms 21868 KB Output is correct
30 Correct 90 ms 11016 KB Output is correct
31 Correct 533 ms 25484 KB Output is correct
32 Correct 495 ms 25516 KB Output is correct
33 Correct 418 ms 25088 KB Output is correct
34 Correct 280 ms 22448 KB Output is correct
35 Correct 156 ms 12924 KB Output is correct
36 Correct 97 ms 11652 KB Output is correct
37 Correct 493 ms 25488 KB Output is correct
38 Correct 554 ms 25368 KB Output is correct
39 Correct 582 ms 25344 KB Output is correct
40 Correct 99 ms 11656 KB Output is correct
41 Correct 243 ms 21756 KB Output is correct
42 Correct 86 ms 11144 KB Output is correct
43 Correct 588 ms 31788 KB Output is correct
44 Correct 599 ms 31740 KB Output is correct
45 Correct 523 ms 31460 KB Output is correct
46 Correct 304 ms 27900 KB Output is correct
47 Correct 183 ms 14204 KB Output is correct
48 Correct 111 ms 11656 KB Output is correct
49 Correct 552 ms 31668 KB Output is correct
50 Correct 546 ms 31592 KB Output is correct
51 Correct 519 ms 31488 KB Output is correct
52 Correct 118 ms 12796 KB Output is correct
53 Correct 264 ms 26776 KB Output is correct