답안 #394229

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
394229 2021-04-26T07:57:00 Z SavicS Examination (JOI19_examination) C++14
43 / 100
235 ms 11152 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[maxn];

    void upd(int x, ll val) {
        while(x <= 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 460 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 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 7 ms 716 KB Output is correct
8 Correct 6 ms 716 KB Output is correct
9 Correct 5 ms 716 KB Output is correct
10 Correct 5 ms 716 KB Output is correct
11 Correct 4 ms 716 KB Output is correct
12 Correct 4 ms 592 KB Output is correct
13 Correct 6 ms 716 KB Output is correct
14 Correct 6 ms 728 KB Output is correct
15 Correct 5 ms 720 KB Output is correct
16 Correct 4 ms 592 KB Output is correct
17 Correct 5 ms 708 KB Output is correct
18 Correct 3 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 8436 KB Output is correct
2 Correct 178 ms 8384 KB Output is correct
3 Correct 176 ms 8332 KB Output is correct
4 Correct 159 ms 7056 KB Output is correct
5 Correct 141 ms 7012 KB Output is correct
6 Correct 116 ms 6204 KB Output is correct
7 Correct 183 ms 8080 KB Output is correct
8 Correct 186 ms 8220 KB Output is correct
9 Correct 194 ms 7952 KB Output is correct
10 Correct 133 ms 7104 KB Output is correct
11 Correct 130 ms 6956 KB Output is correct
12 Correct 108 ms 6240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 8436 KB Output is correct
2 Correct 178 ms 8384 KB Output is correct
3 Correct 176 ms 8332 KB Output is correct
4 Correct 159 ms 7056 KB Output is correct
5 Correct 141 ms 7012 KB Output is correct
6 Correct 116 ms 6204 KB Output is correct
7 Correct 183 ms 8080 KB Output is correct
8 Correct 186 ms 8220 KB Output is correct
9 Correct 194 ms 7952 KB Output is correct
10 Correct 133 ms 7104 KB Output is correct
11 Correct 130 ms 6956 KB Output is correct
12 Correct 108 ms 6240 KB Output is correct
13 Correct 189 ms 8828 KB Output is correct
14 Correct 183 ms 8720 KB Output is correct
15 Correct 176 ms 8380 KB Output is correct
16 Correct 140 ms 7384 KB Output is correct
17 Correct 142 ms 7440 KB Output is correct
18 Correct 119 ms 6176 KB Output is correct
19 Correct 179 ms 8728 KB Output is correct
20 Correct 184 ms 8796 KB Output is correct
21 Correct 201 ms 8720 KB Output is correct
22 Correct 130 ms 6900 KB Output is correct
23 Correct 147 ms 7008 KB Output is correct
24 Correct 95 ms 6252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 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 7 ms 716 KB Output is correct
8 Correct 6 ms 716 KB Output is correct
9 Correct 5 ms 716 KB Output is correct
10 Correct 5 ms 716 KB Output is correct
11 Correct 4 ms 716 KB Output is correct
12 Correct 4 ms 592 KB Output is correct
13 Correct 6 ms 716 KB Output is correct
14 Correct 6 ms 728 KB Output is correct
15 Correct 5 ms 720 KB Output is correct
16 Correct 4 ms 592 KB Output is correct
17 Correct 5 ms 708 KB Output is correct
18 Correct 3 ms 588 KB Output is correct
19 Correct 204 ms 8436 KB Output is correct
20 Correct 178 ms 8384 KB Output is correct
21 Correct 176 ms 8332 KB Output is correct
22 Correct 159 ms 7056 KB Output is correct
23 Correct 141 ms 7012 KB Output is correct
24 Correct 116 ms 6204 KB Output is correct
25 Correct 183 ms 8080 KB Output is correct
26 Correct 186 ms 8220 KB Output is correct
27 Correct 194 ms 7952 KB Output is correct
28 Correct 133 ms 7104 KB Output is correct
29 Correct 130 ms 6956 KB Output is correct
30 Correct 108 ms 6240 KB Output is correct
31 Correct 189 ms 8828 KB Output is correct
32 Correct 183 ms 8720 KB Output is correct
33 Correct 176 ms 8380 KB Output is correct
34 Correct 140 ms 7384 KB Output is correct
35 Correct 142 ms 7440 KB Output is correct
36 Correct 119 ms 6176 KB Output is correct
37 Correct 179 ms 8728 KB Output is correct
38 Correct 184 ms 8796 KB Output is correct
39 Correct 201 ms 8720 KB Output is correct
40 Correct 130 ms 6900 KB Output is correct
41 Correct 147 ms 7008 KB Output is correct
42 Correct 95 ms 6252 KB Output is correct
43 Incorrect 235 ms 11152 KB Output isn't correct
44 Halted 0 ms 0 KB -