답안 #956260

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
956260 2024-04-01T12:26:11 Z _callmelucian Examination (JOI19_examination) C++14
100 / 100
351 ms 12280 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;

#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())

const int mn = 1e5 + 5;
const int srt = 316;

struct strct {
    vector<int> vec, sum;
    strct (int sz) : vec(sz + 1), sum(sz / srt + 1) {}

    void update (int pos, int val) {
        vec[pos] += val;
        sum[pos / srt] += val;
    }

    int query (int k) {
        int nxt = k / srt + 1, ans = 0;
        for (int i = k; i < srt * nxt; i++) ans += vec[i];
        for (int i = nxt; i < sum.size(); i++) ans += sum[i];
        return ans;
    }
} helper(mn);

struct qry {
    int x, y, z, id;

    qry() : x(0), y(0), z(0), id(0) {}
    qry (int a, int b, int c, int d) : x(a), y(b), z(c), id(d) {}

    bool operator < (const qry &o) const {
        if (x / srt == o.x / srt) {
            if ((x / srt) & 1) return y < o.y;
            return y > o.y;
        }
        return x / srt < o.x / srt;
    }
};

int VMO[mn], VOI[mn], ans[mn], idBoth[mn], crit[mn];
vector<pii> math, info, both;

void add (int i) {
    //cout << "add student " << i << " " << crit[i] << "\n";
    if (++crit[i] == 2) helper.update(idBoth[i], 1);
}

void rem (int i) {
    //cout << "remove student " << i << " " << crit[i] << "\n";
    if (crit[i]-- == 2) helper.update(idBoth[i], -1);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, q; cin >> n >> q;
    for (int i = 0; i < n; i++) cin >> VMO[i] >> VOI[i];

    math = info = both = vector<pii>(n);
    for (int i = 0; i < n; i++) {
        math[i] = {VMO[i], i};
        info[i] = {VOI[i], i};
        both[i] = {VMO[i] + VOI[i], i};
    }
    sort(all(math));
    sort(all(info));
    sort(all(both));

    for (int i = 0; i < n; i++)
        idBoth[i] = lower_bound(all(both), make_pair(VMO[i] + VOI[i], i)) - both.begin();

    vector<qry> query;
    for (int i = 0; i < q; i++) {
        int a, b, c; cin >> a >> b >> c;
        int x = lower_bound(all(math), make_pair(a, 0)) - math.begin();
        int y = lower_bound(all(info), make_pair(b, 0)) - info.begin();
        int z = lower_bound(all(both), make_pair(c, 0)) - both.begin();
        if (x < n && y < n && z < n)
            query.push_back(qry(x, y, z, i));
    }
    sort(all(query));

    int iterM = n, iterI = n;
    for (qry cur : query) {
        while (iterM > cur.x) add(math[--iterM].second);
        while (iterM < cur.x) rem(math[iterM++].second);
        while (iterI > cur.y) add(info[--iterI].second);
        while (iterI < cur.y) rem(info[iterI++].second);

        ans[cur.id] = helper.query(cur.z);
    }

    for (int i = 0; i < q; i++) cout << ans[i] << "\n";

    return 0;
}

Compilation message

examination.cpp: In member function 'int strct::query(int)':
examination.cpp:28:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for (int i = nxt; i < sum.size(); i++) ans += sum[i];
      |                           ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 6 ms 1116 KB Output is correct
8 Correct 5 ms 1280 KB Output is correct
9 Correct 6 ms 1140 KB Output is correct
10 Correct 5 ms 1144 KB Output is correct
11 Correct 4 ms 1232 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 5 ms 1256 KB Output is correct
14 Correct 5 ms 1116 KB Output is correct
15 Correct 6 ms 1120 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 342 ms 9884 KB Output is correct
2 Correct 338 ms 9876 KB Output is correct
3 Correct 343 ms 10020 KB Output is correct
4 Correct 261 ms 8972 KB Output is correct
5 Correct 144 ms 9132 KB Output is correct
6 Correct 110 ms 8392 KB Output is correct
7 Correct 180 ms 9768 KB Output is correct
8 Correct 198 ms 9676 KB Output is correct
9 Correct 151 ms 9696 KB Output is correct
10 Correct 93 ms 8144 KB Output is correct
11 Correct 108 ms 8140 KB Output is correct
12 Correct 45 ms 6420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 342 ms 9884 KB Output is correct
2 Correct 338 ms 9876 KB Output is correct
3 Correct 343 ms 10020 KB Output is correct
4 Correct 261 ms 8972 KB Output is correct
5 Correct 144 ms 9132 KB Output is correct
6 Correct 110 ms 8392 KB Output is correct
7 Correct 180 ms 9768 KB Output is correct
8 Correct 198 ms 9676 KB Output is correct
9 Correct 151 ms 9696 KB Output is correct
10 Correct 93 ms 8144 KB Output is correct
11 Correct 108 ms 8140 KB Output is correct
12 Correct 45 ms 6420 KB Output is correct
13 Correct 333 ms 10144 KB Output is correct
14 Correct 337 ms 10128 KB Output is correct
15 Correct 344 ms 9736 KB Output is correct
16 Correct 266 ms 9424 KB Output is correct
17 Correct 131 ms 9444 KB Output is correct
18 Correct 101 ms 8336 KB Output is correct
19 Correct 325 ms 10300 KB Output is correct
20 Correct 340 ms 10636 KB Output is correct
21 Correct 217 ms 10184 KB Output is correct
22 Correct 92 ms 8208 KB Output is correct
23 Correct 112 ms 8020 KB Output is correct
24 Correct 51 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 6 ms 1116 KB Output is correct
8 Correct 5 ms 1280 KB Output is correct
9 Correct 6 ms 1140 KB Output is correct
10 Correct 5 ms 1144 KB Output is correct
11 Correct 4 ms 1232 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 5 ms 1256 KB Output is correct
14 Correct 5 ms 1116 KB Output is correct
15 Correct 6 ms 1120 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 342 ms 9884 KB Output is correct
20 Correct 338 ms 9876 KB Output is correct
21 Correct 343 ms 10020 KB Output is correct
22 Correct 261 ms 8972 KB Output is correct
23 Correct 144 ms 9132 KB Output is correct
24 Correct 110 ms 8392 KB Output is correct
25 Correct 180 ms 9768 KB Output is correct
26 Correct 198 ms 9676 KB Output is correct
27 Correct 151 ms 9696 KB Output is correct
28 Correct 93 ms 8144 KB Output is correct
29 Correct 108 ms 8140 KB Output is correct
30 Correct 45 ms 6420 KB Output is correct
31 Correct 333 ms 10144 KB Output is correct
32 Correct 337 ms 10128 KB Output is correct
33 Correct 344 ms 9736 KB Output is correct
34 Correct 266 ms 9424 KB Output is correct
35 Correct 131 ms 9444 KB Output is correct
36 Correct 101 ms 8336 KB Output is correct
37 Correct 325 ms 10300 KB Output is correct
38 Correct 340 ms 10636 KB Output is correct
39 Correct 217 ms 10184 KB Output is correct
40 Correct 92 ms 8208 KB Output is correct
41 Correct 112 ms 8020 KB Output is correct
42 Correct 51 ms 6480 KB Output is correct
43 Correct 336 ms 12236 KB Output is correct
44 Correct 351 ms 12280 KB Output is correct
45 Correct 348 ms 12236 KB Output is correct
46 Correct 280 ms 10676 KB Output is correct
47 Correct 133 ms 10656 KB Output is correct
48 Correct 83 ms 7372 KB Output is correct
49 Correct 186 ms 12104 KB Output is correct
50 Correct 189 ms 11980 KB Output is correct
51 Correct 162 ms 11980 KB Output is correct
52 Correct 107 ms 9600 KB Output is correct
53 Correct 111 ms 8876 KB Output is correct