Submission #369656

# Submission time Handle Problem Language Result Execution time Memory
369656 2021-02-22T07:37:00 Z CodePlatina Examination (JOI19_examination) C++14
100 / 100
393 ms 32992 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <tuple>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define piii pair<int, pii>
#define plll pair<long long, pll>
#define tiii tuple<int, int, int>
#define tiiii tuple<int, int, int, int>
#define tlll tuple<long long, long long, long long>
#define tllll tuple<long long, long long, long long, long long>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss
#define DEBUG

using namespace std;

int ps[101010];
vector<int> prX;
vector<int> prY;
vector<int> prP;
vector<tiii> lsX[101010];
vector<int> pntX[101010];
vector<tiii> lsPX[101010];
vector<int> pntPX[101010];
vector<tiii> lsPY[101010];
vector<int> pntPY[101010];

int N;
int ind[202020];
void init(void)
{
    for(int i = 0; i < 202020; ++i)
        ind[i] = 0;
}
void upd(int pos)
{
    pos += N;
    ++ind[pos];
    while(pos >>= 1) ++ind[pos];
}
int qr(int l, int r)
{
    int ret = 0;
    for(int x = l + N, y = r + N; x != y; x >>= 1, y >>= 1)
    {
        if(x & 1) ret += ind[x++];
        if(y & 1) ret += ind[--y];
    }
    return ret;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, T; cin >> n >> T;
    pii A[n]; tiii B[T];
    for(auto &i : A) cin >> i.ff >> i.ss;
    for(auto &[a, b, c] : B) cin >> a >> b >> c;

    for(auto &i : A)
    {
        prX.push_back(i.ff);
        prY.push_back(i.ss);
        prP.push_back(i.ff + i.ss);
    }

    sort(prX.begin(), prX.end());
    prX.resize(unique(prX.begin(), prX.end()) - prX.begin());
    sort(prY.begin(), prY.end());
    prY.resize(unique(prY.begin(), prY.end()) - prY.begin());
    sort(prP.begin(), prP.end());
    prP.resize(unique(prP.begin(), prP.end()) - prP.begin());

    for(auto &i : A)
    {
        int x = lower_bound(prX.begin(), prX.end(), i.ff) - prX.begin();
        int y = lower_bound(prY.begin(), prY.end(), i.ss) - prY.begin();
        int p = lower_bound(prP.begin(), prP.end(), i.ff + i.ss) - prP.begin();
        ++ps[p];
        pntX[x].push_back(y);
        pntPX[x].push_back(p);
        pntPY[y].push_back(p);
    }
    for(int i = (int)prP.size() - 2; i >= 0; --i) ps[i] += ps[i + 1];

    int ans[T]{};
    for(int i = 0; i < T; ++i)
    {
        auto [a, b, c] = B[i];

        int x = lower_bound(prX.begin(), prX.end(), a) - prX.begin();
        int y = lower_bound(prY.begin(), prY.end(), b) - prY.begin();
        int p = lower_bound(prP.begin(), prP.end(), c) - prP.begin();

        if(c <= a + b)
        {
            lsX[x].push_back({i, y, (int)prY.size()});
        }
        else
        {
            lsPX[x].push_back({i, p, (int)prP.size()});
            lsPY[y].push_back({i, p, (int)prP.size()});
            ans[i] = ps[p];
        }
    }

    N = prY.size();
    for(int i = (int)prX.size(); i >= 0; --i)
    {
        for(auto j : pntX[i]) upd(j);
        for(auto [j, l, r] : lsX[i]) ans[j] += qr(l, r);
    }

    N = prP.size();
    init();
    for(int i = 0; i <= (int)prP.size(); ++i)
    {
        for(auto [j, l, r] : lsPX[i]) ans[j] -= qr(l, r);
        for(auto j : pntPX[i]) upd(j);
    }

    init();
    for(int i = 0; i <= (int)prP.size(); ++i)
    {
        for(auto [j, l, r] : lsPY[i]) ans[j] -= qr(l, r);
        for(auto j : pntPY[i]) upd(j);
    }

    for(int i = 0; i < T; ++i) cout << ans[i] << '\n';
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:65:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   65 |     for(auto &[a, b, c] : B) cin >> a >> b >> c;
      |               ^
examination.cpp:96:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   96 |         auto [a, b, c] = B[i];
      |              ^
examination.cpp:118:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  118 |         for(auto [j, l, r] : lsX[i]) ans[j] += qr(l, r);
      |                  ^
examination.cpp:125:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  125 |         for(auto [j, l, r] : lsPX[i]) ans[j] -= qr(l, r);
      |                  ^
examination.cpp:132:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  132 |         for(auto [j, l, r] : lsPY[i]) ans[j] -= qr(l, r);
      |                  ^
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15340 KB Output is correct
2 Correct 11 ms 15340 KB Output is correct
3 Correct 11 ms 15340 KB Output is correct
4 Correct 11 ms 15340 KB Output is correct
5 Correct 11 ms 15340 KB Output is correct
6 Correct 12 ms 15340 KB Output is correct
7 Correct 18 ms 15852 KB Output is correct
8 Correct 17 ms 15852 KB Output is correct
9 Correct 19 ms 15852 KB Output is correct
10 Correct 16 ms 15852 KB Output is correct
11 Correct 18 ms 15872 KB Output is correct
12 Correct 13 ms 15724 KB Output is correct
13 Correct 16 ms 15852 KB Output is correct
14 Correct 16 ms 15852 KB Output is correct
15 Correct 16 ms 15852 KB Output is correct
16 Correct 15 ms 15852 KB Output is correct
17 Correct 16 ms 15852 KB Output is correct
18 Correct 13 ms 15596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 296 ms 27876 KB Output is correct
2 Correct 297 ms 27872 KB Output is correct
3 Correct 290 ms 27872 KB Output is correct
4 Correct 206 ms 26208 KB Output is correct
5 Correct 165 ms 24672 KB Output is correct
6 Correct 86 ms 23392 KB Output is correct
7 Correct 297 ms 27616 KB Output is correct
8 Correct 282 ms 27872 KB Output is correct
9 Correct 290 ms 27744 KB Output is correct
10 Correct 155 ms 24156 KB Output is correct
11 Correct 182 ms 25952 KB Output is correct
12 Correct 66 ms 21852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 296 ms 27876 KB Output is correct
2 Correct 297 ms 27872 KB Output is correct
3 Correct 290 ms 27872 KB Output is correct
4 Correct 206 ms 26208 KB Output is correct
5 Correct 165 ms 24672 KB Output is correct
6 Correct 86 ms 23392 KB Output is correct
7 Correct 297 ms 27616 KB Output is correct
8 Correct 282 ms 27872 KB Output is correct
9 Correct 290 ms 27744 KB Output is correct
10 Correct 155 ms 24156 KB Output is correct
11 Correct 182 ms 25952 KB Output is correct
12 Correct 66 ms 21852 KB Output is correct
13 Correct 350 ms 29196 KB Output is correct
14 Correct 318 ms 28536 KB Output is correct
15 Correct 291 ms 27872 KB Output is correct
16 Correct 228 ms 27360 KB Output is correct
17 Correct 202 ms 25696 KB Output is correct
18 Correct 94 ms 23136 KB Output is correct
19 Correct 341 ms 29152 KB Output is correct
20 Correct 341 ms 28768 KB Output is correct
21 Correct 323 ms 29280 KB Output is correct
22 Correct 155 ms 23648 KB Output is correct
23 Correct 188 ms 26044 KB Output is correct
24 Correct 65 ms 21980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15340 KB Output is correct
2 Correct 11 ms 15340 KB Output is correct
3 Correct 11 ms 15340 KB Output is correct
4 Correct 11 ms 15340 KB Output is correct
5 Correct 11 ms 15340 KB Output is correct
6 Correct 12 ms 15340 KB Output is correct
7 Correct 18 ms 15852 KB Output is correct
8 Correct 17 ms 15852 KB Output is correct
9 Correct 19 ms 15852 KB Output is correct
10 Correct 16 ms 15852 KB Output is correct
11 Correct 18 ms 15872 KB Output is correct
12 Correct 13 ms 15724 KB Output is correct
13 Correct 16 ms 15852 KB Output is correct
14 Correct 16 ms 15852 KB Output is correct
15 Correct 16 ms 15852 KB Output is correct
16 Correct 15 ms 15852 KB Output is correct
17 Correct 16 ms 15852 KB Output is correct
18 Correct 13 ms 15596 KB Output is correct
19 Correct 296 ms 27876 KB Output is correct
20 Correct 297 ms 27872 KB Output is correct
21 Correct 290 ms 27872 KB Output is correct
22 Correct 206 ms 26208 KB Output is correct
23 Correct 165 ms 24672 KB Output is correct
24 Correct 86 ms 23392 KB Output is correct
25 Correct 297 ms 27616 KB Output is correct
26 Correct 282 ms 27872 KB Output is correct
27 Correct 290 ms 27744 KB Output is correct
28 Correct 155 ms 24156 KB Output is correct
29 Correct 182 ms 25952 KB Output is correct
30 Correct 66 ms 21852 KB Output is correct
31 Correct 350 ms 29196 KB Output is correct
32 Correct 318 ms 28536 KB Output is correct
33 Correct 291 ms 27872 KB Output is correct
34 Correct 228 ms 27360 KB Output is correct
35 Correct 202 ms 25696 KB Output is correct
36 Correct 94 ms 23136 KB Output is correct
37 Correct 341 ms 29152 KB Output is correct
38 Correct 341 ms 28768 KB Output is correct
39 Correct 323 ms 29280 KB Output is correct
40 Correct 155 ms 23648 KB Output is correct
41 Correct 188 ms 26044 KB Output is correct
42 Correct 65 ms 21980 KB Output is correct
43 Correct 390 ms 32736 KB Output is correct
44 Correct 392 ms 32736 KB Output is correct
45 Correct 373 ms 31968 KB Output is correct
46 Correct 264 ms 29792 KB Output is correct
47 Correct 221 ms 26976 KB Output is correct
48 Correct 90 ms 23520 KB Output is correct
49 Correct 379 ms 32096 KB Output is correct
50 Correct 393 ms 32992 KB Output is correct
51 Correct 377 ms 32732 KB Output is correct
52 Correct 218 ms 26104 KB Output is correct
53 Correct 222 ms 28640 KB Output is correct