Submission #477820

# Submission time Handle Problem Language Result Execution time Memory
477820 2021-10-04T02:42:07 Z Mike4235 Examination (JOI19_examination) C++17
100 / 100
1431 ms 69320 KB
/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")*/
// only when really needed

/* GNU G++17 7.3.0: No long long for faster code
   GNU G++17 9.2.0 (64 bit, msys 2): Long long only for faster code */
 
#include <bits/stdc++.h>
  
#define for1(i,a,b) for (int i = a; i <= b; i++)
#define for2(i,a,b) for (int i = a; i >= b; i--)
#define int long long

#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pb push_back
 
/*
__builtin_popcountll(x) : Number of 1-bit
__builtin_ctzll(x) : Number of trailing 0
*/
 
#define PI 3.1415926535897932384626433832795
#define INF 1000000000000000000
#define MOD 1000000007
#define MOD2 1000000009
#define EPS 1e-6

using namespace std;

struct Point{
    int x, y, z, id, ans;
    bool operator< (Point const& o) {
        if (x != o.x) return x > o.x;
        if (y != o.y) return y < o.y;
        return z < o.z;
    }
};

const int k = 6e5;

int n, q;
map<int, int> mp;
int res[100005], fentree[600005];
vector<Point> v;

void update(int i, int val) {
    for (; i <= k; i += i & -i) fentree[i] += val;
}

int get(int i) {
    int res = 0;
    for (; i; i -= i & -i) res += fentree[i];
    return res;
}

void cdq(int l, int r) {
    if (l == r) return;
    int m = (l + r)/2;
    cdq(l, m); cdq(m + 1, r);

    // cout << l << " " << r << "\n";
    // for1(i,l,r) cout << v[i].x << " " << v[i].y << " " << v[i].z << "\n";
    vector<Point> st;
    vector<int> roll;
    int a = l, b = m + 1, sum = 0;

    while (a <= m && b <= r) {
        if (v[a].y > v[b].y) {
            if (!v[a].id) {
                sum++;
                update(v[a].z, 1);
                roll.push_back(v[a].z);
            }
            st.push_back(v[a++]);
        }
        else {
            if (v[b].id) res[v[b].id] += sum - get(v[b].z);
            // cout << v[b].x << " " << v[b].y << " " << v[b].z << " " << v[b].id << " " << sum - get(v[b].z) << "\n";
            st.push_back(v[b++]);
        }
    }

    while (a <= m) st.push_back(v[a++]);
    while (b <= r) {
        if (v[b].id) res[v[b].id] += sum - get(v[b].z);
        // cout << v[b].x << " " << v[b].y << " " << v[b].z << " " << v[b].id << " " << sum - get(v[b].z) << "\n";
        st.push_back(v[b++]);
    }
    // cout << "\n";

    for1(i,l,r) v[i] = st[i - l];
    for (auto x : roll) update(x, -1);
}

signed main() {
    
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    // freopen("cf.inp", "r", stdin);
    // freopen("cf.out", "w", stdout);

    cin >> n >> q;
    for1(i,1,n) {
        int a, b;
        cin >> a >> b;
        v.push_back({a, b, a + b, 0, 0});
        mp[a] = 0;
        mp[b] = 0;
        mp[a + b] = 0;
    }

    for1(i,1,q) {
        int x, y, z;
        cin >> x >> y >> z;
        x--; y--; z--;
        v.push_back({x, y, z, i, 0});
        mp[x] = 0;
        mp[y] = 0;
        mp[z] = 0;
    }

    int cur = 0;
    for (auto &p : mp) p.second = ++cur;
    for (auto &p : v) p.x = mp[p.x], p.y = mp[p.y], p.z = mp[p.z];

    sort(v.begin(), v.end());

    cdq(0, n + q - 1);

    // for (auto p : v) cout << p.x << " " << p.y << " " << p.z << " " << p.id << " " << p.ans << "\n";
    // cout << "\n";
    // for (auto p : s) cout << p.x << " " << p.y << " " << p.z << " " << p.id << " " << p.ans << "\n";
    // cout << "\n";

    for1(i,1,q) cout << res[i] << "\n";
    
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 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 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 15 ms 2296 KB Output is correct
8 Correct 15 ms 2360 KB Output is correct
9 Correct 21 ms 2296 KB Output is correct
10 Correct 15 ms 1908 KB Output is correct
11 Correct 15 ms 1912 KB Output is correct
12 Correct 8 ms 1116 KB Output is correct
13 Correct 14 ms 2104 KB Output is correct
14 Correct 15 ms 2108 KB Output is correct
15 Correct 14 ms 2168 KB Output is correct
16 Correct 7 ms 1408 KB Output is correct
17 Correct 10 ms 1736 KB Output is correct
18 Correct 4 ms 1012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 668 ms 36636 KB Output is correct
2 Correct 626 ms 36640 KB Output is correct
3 Correct 621 ms 36552 KB Output is correct
4 Correct 435 ms 33696 KB Output is correct
5 Correct 393 ms 33768 KB Output is correct
6 Correct 191 ms 27000 KB Output is correct
7 Correct 641 ms 36432 KB Output is correct
8 Correct 648 ms 36428 KB Output is correct
9 Correct 582 ms 36180 KB Output is correct
10 Correct 334 ms 33116 KB Output is correct
11 Correct 431 ms 33132 KB Output is correct
12 Correct 169 ms 26988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 668 ms 36636 KB Output is correct
2 Correct 626 ms 36640 KB Output is correct
3 Correct 621 ms 36552 KB Output is correct
4 Correct 435 ms 33696 KB Output is correct
5 Correct 393 ms 33768 KB Output is correct
6 Correct 191 ms 27000 KB Output is correct
7 Correct 641 ms 36432 KB Output is correct
8 Correct 648 ms 36428 KB Output is correct
9 Correct 582 ms 36180 KB Output is correct
10 Correct 334 ms 33116 KB Output is correct
11 Correct 431 ms 33132 KB Output is correct
12 Correct 169 ms 26988 KB Output is correct
13 Correct 784 ms 38296 KB Output is correct
14 Correct 781 ms 36592 KB Output is correct
15 Correct 650 ms 36660 KB Output is correct
16 Correct 500 ms 33856 KB Output is correct
17 Correct 497 ms 33960 KB Output is correct
18 Correct 203 ms 27140 KB Output is correct
19 Correct 810 ms 38276 KB Output is correct
20 Correct 781 ms 37396 KB Output is correct
21 Correct 850 ms 38340 KB Output is correct
22 Correct 430 ms 33072 KB Output is correct
23 Correct 384 ms 33148 KB Output is correct
24 Correct 151 ms 27124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 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 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 15 ms 2296 KB Output is correct
8 Correct 15 ms 2360 KB Output is correct
9 Correct 21 ms 2296 KB Output is correct
10 Correct 15 ms 1908 KB Output is correct
11 Correct 15 ms 1912 KB Output is correct
12 Correct 8 ms 1116 KB Output is correct
13 Correct 14 ms 2104 KB Output is correct
14 Correct 15 ms 2108 KB Output is correct
15 Correct 14 ms 2168 KB Output is correct
16 Correct 7 ms 1408 KB Output is correct
17 Correct 10 ms 1736 KB Output is correct
18 Correct 4 ms 1012 KB Output is correct
19 Correct 668 ms 36636 KB Output is correct
20 Correct 626 ms 36640 KB Output is correct
21 Correct 621 ms 36552 KB Output is correct
22 Correct 435 ms 33696 KB Output is correct
23 Correct 393 ms 33768 KB Output is correct
24 Correct 191 ms 27000 KB Output is correct
25 Correct 641 ms 36432 KB Output is correct
26 Correct 648 ms 36428 KB Output is correct
27 Correct 582 ms 36180 KB Output is correct
28 Correct 334 ms 33116 KB Output is correct
29 Correct 431 ms 33132 KB Output is correct
30 Correct 169 ms 26988 KB Output is correct
31 Correct 784 ms 38296 KB Output is correct
32 Correct 781 ms 36592 KB Output is correct
33 Correct 650 ms 36660 KB Output is correct
34 Correct 500 ms 33856 KB Output is correct
35 Correct 497 ms 33960 KB Output is correct
36 Correct 203 ms 27140 KB Output is correct
37 Correct 810 ms 38276 KB Output is correct
38 Correct 781 ms 37396 KB Output is correct
39 Correct 850 ms 38340 KB Output is correct
40 Correct 430 ms 33072 KB Output is correct
41 Correct 384 ms 33148 KB Output is correct
42 Correct 151 ms 27124 KB Output is correct
43 Correct 1431 ms 69320 KB Output is correct
44 Correct 1333 ms 69276 KB Output is correct
45 Correct 1324 ms 69276 KB Output is correct
46 Correct 810 ms 54592 KB Output is correct
47 Correct 811 ms 54556 KB Output is correct
48 Correct 202 ms 26992 KB Output is correct
49 Correct 1319 ms 69192 KB Output is correct
50 Correct 1270 ms 69180 KB Output is correct
51 Correct 1246 ms 68880 KB Output is correct
52 Correct 625 ms 48264 KB Output is correct
53 Correct 471 ms 41120 KB Output is correct