답안 #394230

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
394230 2021-04-26T07:57:55 Z SavicS Examination (JOI19_examination) C++14
100 / 100
216 ms 12456 KB
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 100005;
const int inf = 1e9 + 5;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k)  print the k-th smallest number in os(0-based)

int n, q;

array<int,4> niz[maxn];
array<int,4> upit[maxn];

int res[maxn];

struct fenwik {
    ll dud[2 * maxn];

    void upd(int x, ll val) {
        while(x <= 2 * maxn) {
            dud[x] += val;
            x += x&(-x);
        }
    }

    ll query(int x) {
        ll sum = 0;
        while(x > 0) {
            sum += dud[x];
            x -= x&(-x);
        }
        return sum;
    }

} fw[2];

int main() 
{
    ios::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
    cin >> n >> q;
    ff(i,1,n) {
        int S, T;
        cin >> S >> T;
        niz[i] = {S + T, S, T, i};
    }

    ff(i,1,q) {
        int A, B, C;
        cin >> A >> B >> C;
        C = max(C, A + B);
        upit[i] = {C, A, B, i};
    }

    {
        vector<int> all;
        ff(i,1,n)all.pb(niz[i][1]);
        ff(i,1,q)all.pb(upit[i][1]);
        sort(all(all));
        all.erase(unique(all(all)), all.end());
        ff(i,1,n)niz[i][1] = lower_bound(all(all), niz[i][1]) - all.begin() + 1;
        ff(i,1,q)upit[i][1] = lower_bound(all(all), upit[i][1]) - all.begin() + 1;
    }

    {
        vector<int> all;
        ff(i,1,n)all.pb(niz[i][2]);
        ff(i,1,q)all.pb(upit[i][2]);
        sort(all(all));
        all.erase(unique(all(all)), all.end());
        ff(i,1,n)niz[i][2] = lower_bound(all(all), niz[i][2]) - all.begin() + 1;
        ff(i,1,q)upit[i][2] = lower_bound(all(all), upit[i][2]) - all.begin() + 1;
    }

    sort(niz + 1, niz + n + 1);
    reverse(niz + 1, niz + n + 1);

    sort(upit + 1, upit + q + 1);
    reverse(upit + 1, upit + q + 1);

    int j = 0;
    ff(i,1,q) {

        while(j + 1 <= n && niz[j + 1][0] >= upit[i][0]) {
            j += 1;
            fw[0].upd(niz[j][1], 1);
            fw[1].upd(niz[j][2], 1);
        }

        res[upit[i][3]] = j - fw[0].query(upit[i][1] - 1) - fw[1].query(upit[i][2] - 1);

    }

    ff(i,1,q)cout << res[i] << '\n';

    return 0;
}
/**



// probati bojenje sahovski ili slicno

**/


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 5 ms 588 KB Output is correct
8 Correct 7 ms 588 KB Output is correct
9 Correct 5 ms 620 KB Output is correct
10 Correct 4 ms 588 KB Output is correct
11 Correct 4 ms 588 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 5 ms 588 KB Output is correct
14 Correct 5 ms 616 KB Output is correct
15 Correct 5 ms 588 KB Output is correct
16 Correct 4 ms 588 KB Output is correct
17 Correct 4 ms 620 KB Output is correct
18 Correct 3 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 176 ms 5904 KB Output is correct
2 Correct 175 ms 5848 KB Output is correct
3 Correct 176 ms 5872 KB Output is correct
4 Correct 139 ms 5252 KB Output is correct
5 Correct 135 ms 5264 KB Output is correct
6 Correct 110 ms 5168 KB Output is correct
7 Correct 185 ms 5748 KB Output is correct
8 Correct 168 ms 5744 KB Output is correct
9 Correct 162 ms 5584 KB Output is correct
10 Correct 132 ms 5360 KB Output is correct
11 Correct 129 ms 5240 KB Output is correct
12 Correct 92 ms 5256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 176 ms 5904 KB Output is correct
2 Correct 175 ms 5848 KB Output is correct
3 Correct 176 ms 5872 KB Output is correct
4 Correct 139 ms 5252 KB Output is correct
5 Correct 135 ms 5264 KB Output is correct
6 Correct 110 ms 5168 KB Output is correct
7 Correct 185 ms 5748 KB Output is correct
8 Correct 168 ms 5744 KB Output is correct
9 Correct 162 ms 5584 KB Output is correct
10 Correct 132 ms 5360 KB Output is correct
11 Correct 129 ms 5240 KB Output is correct
12 Correct 92 ms 5256 KB Output is correct
13 Correct 175 ms 5780 KB Output is correct
14 Correct 178 ms 5876 KB Output is correct
15 Correct 198 ms 5908 KB Output is correct
16 Correct 142 ms 5224 KB Output is correct
17 Correct 143 ms 5240 KB Output is correct
18 Correct 129 ms 5252 KB Output is correct
19 Correct 178 ms 5800 KB Output is correct
20 Correct 177 ms 5956 KB Output is correct
21 Correct 182 ms 5868 KB Output is correct
22 Correct 131 ms 5304 KB Output is correct
23 Correct 134 ms 5300 KB Output is correct
24 Correct 96 ms 5424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 5 ms 588 KB Output is correct
8 Correct 7 ms 588 KB Output is correct
9 Correct 5 ms 620 KB Output is correct
10 Correct 4 ms 588 KB Output is correct
11 Correct 4 ms 588 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 5 ms 588 KB Output is correct
14 Correct 5 ms 616 KB Output is correct
15 Correct 5 ms 588 KB Output is correct
16 Correct 4 ms 588 KB Output is correct
17 Correct 4 ms 620 KB Output is correct
18 Correct 3 ms 492 KB Output is correct
19 Correct 176 ms 5904 KB Output is correct
20 Correct 175 ms 5848 KB Output is correct
21 Correct 176 ms 5872 KB Output is correct
22 Correct 139 ms 5252 KB Output is correct
23 Correct 135 ms 5264 KB Output is correct
24 Correct 110 ms 5168 KB Output is correct
25 Correct 185 ms 5748 KB Output is correct
26 Correct 168 ms 5744 KB Output is correct
27 Correct 162 ms 5584 KB Output is correct
28 Correct 132 ms 5360 KB Output is correct
29 Correct 129 ms 5240 KB Output is correct
30 Correct 92 ms 5256 KB Output is correct
31 Correct 175 ms 5780 KB Output is correct
32 Correct 178 ms 5876 KB Output is correct
33 Correct 198 ms 5908 KB Output is correct
34 Correct 142 ms 5224 KB Output is correct
35 Correct 143 ms 5240 KB Output is correct
36 Correct 129 ms 5252 KB Output is correct
37 Correct 178 ms 5800 KB Output is correct
38 Correct 177 ms 5956 KB Output is correct
39 Correct 182 ms 5868 KB Output is correct
40 Correct 131 ms 5304 KB Output is correct
41 Correct 134 ms 5300 KB Output is correct
42 Correct 96 ms 5424 KB Output is correct
43 Correct 211 ms 7652 KB Output is correct
44 Correct 205 ms 12456 KB Output is correct
45 Correct 216 ms 12384 KB Output is correct
46 Correct 183 ms 9316 KB Output is correct
47 Correct 156 ms 9456 KB Output is correct
48 Correct 123 ms 6272 KB Output is correct
49 Correct 198 ms 12408 KB Output is correct
50 Correct 196 ms 12340 KB Output is correct
51 Correct 192 ms 12316 KB Output is correct
52 Correct 145 ms 9160 KB Output is correct
53 Correct 140 ms 8368 KB Output is correct