Submission #140848

# Submission time Handle Problem Language Result Execution time Memory
140848 2019-08-05T16:11:55 Z karma Examination (JOI19_examination) C++11
100 / 100
1946 ms 774712 KB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FileName      "test"
#define ll            long long
#define ld            long double
#define ull           unsigned long long
#define Debug(x)      cerr << #x << "is " << x << '\n';
#define pb            emplace_back
#define mp            make_pair
#define x             first
#define y             second
//#define LuckyAurora
//#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

using namespace std;
using namespace __gnu_pbds;

template<typename T> inline void Cin(T &x)
{
    char c;
    T sign = 1;
    x = 0;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        if (c == '-') sign = -1;
    for (; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
    x *= sign;
}
template <typename T> inline void Out(T x) {if(x > 9) Out(x / 10); putchar(x % 10 + '0');}
template <typename T> inline void Cout(T x, char c) {if(x < 0) putchar('-'); x = abs(x); Out(x); putchar(c);}
template <typename T, typename... Args> inline void Cin(T& a, Args&... args) {Cin(a);Cin(args...);}
template <typename T, typename... Args> inline void Cout(T a, char c, Args... args) {Cout(a, c);Cout(args...);}

typedef pair<int, int> pii;
const int N = int(1e5) + 7;

bool Get(int x, int i) {return (x >> i) & 1;}
struct TTrie {TTrie* chil[2]; int cur;} *irene[N];
typedef TTrie* PTrie;
PTrie Node()
{
      PTrie ptr = new TTrie();
      ptr -> chil[0] = ptr -> chil[1] = NULL, ptr -> cur = 0;
      return ptr;
}
void Update(int x, PTrie ptr)
{
     bool bit; ++ptr -> cur;
     for(int i = 30; i >= 0; --i) {
        bit = Get(x, i);
        if(ptr -> chil[bit] == NULL) ptr -> chil[bit] = Node();
        ptr = ptr -> chil[bit];
        ++ptr -> cur;
     }
}
int Count(int x, PTrie ptr)
{
    int res = ptr -> cur; bool bit;
    for(int i = 30; i >= 0; --i) {
        bit = Get(x, i);
        if(bit && ptr -> chil[0]) res -= ptr -> chil[0] -> cur;
        if(ptr -> chil[bit] == NULL) return res;
        ptr = ptr -> chil[bit];
    }
    return res;
}

void Update(int x, int y)
{
     for(; x < N; x += (x & -x)) Update(y, irene[x]);
}

int Query(int x, int y)
{
    int res = 0;
    for(; x > 0; x -= (x & -x)) res += Count(y, irene[x]);
    return res;
}

int n, Q;
vector<int> v, res;
vector<pii> a;
struct TQuery
{
    int a, b, c, id;
    bool operator <(const TQuery& other)const& {
        return a > other.a;
    }
};
vector<TQuery> q;

void Enter()
{
     Cin(n, Q); q.resize(Q); a.resize(n); res.resize(Q);
     for(pii& p: a) Cin(p.x, p.y), v.pb(p.y);
     sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
     sort(a.begin(), a.end(), [](const pii& a, const pii& b){return a.x > b.x;});
}

void Solve()
{
     for(int i = 0; i < Q; ++i) Cin(q[i].a, q[i].b, q[i].c), q[i].id = i;
     sort(q.begin(), q.end());
     for(int i = 0; i < N; ++i) irene[i] = Node();
     int j = 0, p;
     for(TQuery que: q) {
         while(a[j].x >= que.a && j < n) {
            p = lower_bound(v.begin(), v.end(), a[j].y) - v.begin() + 1;
            Update(p, a[j].x + a[j].y);
            ++j;
         }
         p = lower_bound(v.begin(), v.end(), que.b) - v.begin();
         res[que.id] = Query(N - 1, que.c) - Query(p, que.c);
     }
     for(int i = 0; i < Q; ++i) cout << res[i] << '\n';
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if(fopen(FileName".inp", "r")) {
        freopen(FileName".inp", "r", stdin);
        freopen(FileName".out", "w", stdout);
    }

    /*int nTest; cin >> nTest;
    while(nTest --)*/ Enter(), Solve();

    return 0;
}

Compilation message

examination.cpp:15:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
examination.cpp: In function 'int main()':
examination.cpp:127:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(FileName".inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:128:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(FileName".out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4216 KB Output is correct
2 Correct 8 ms 4344 KB Output is correct
3 Correct 8 ms 4344 KB Output is correct
4 Correct 8 ms 4344 KB Output is correct
5 Correct 8 ms 4344 KB Output is correct
6 Correct 8 ms 4348 KB Output is correct
7 Correct 61 ms 29048 KB Output is correct
8 Correct 58 ms 29048 KB Output is correct
9 Correct 58 ms 29048 KB Output is correct
10 Correct 61 ms 33016 KB Output is correct
11 Correct 57 ms 26260 KB Output is correct
12 Correct 14 ms 4472 KB Output is correct
13 Correct 57 ms 29020 KB Output is correct
14 Correct 57 ms 29088 KB Output is correct
15 Correct 59 ms 29176 KB Output is correct
16 Correct 54 ms 26232 KB Output is correct
17 Correct 65 ms 35448 KB Output is correct
18 Correct 14 ms 4344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1355 ms 284872 KB Output is correct
2 Correct 1326 ms 285004 KB Output is correct
3 Correct 1421 ms 284876 KB Output is correct
4 Correct 404 ms 95604 KB Output is correct
5 Correct 972 ms 114764 KB Output is correct
6 Correct 218 ms 8052 KB Output is correct
7 Correct 1328 ms 284660 KB Output is correct
8 Correct 1219 ms 284788 KB Output is correct
9 Correct 1227 ms 284788 KB Output is correct
10 Correct 794 ms 108708 KB Output is correct
11 Correct 412 ms 90976 KB Output is correct
12 Correct 207 ms 7664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1355 ms 284872 KB Output is correct
2 Correct 1326 ms 285004 KB Output is correct
3 Correct 1421 ms 284876 KB Output is correct
4 Correct 404 ms 95604 KB Output is correct
5 Correct 972 ms 114764 KB Output is correct
6 Correct 218 ms 8052 KB Output is correct
7 Correct 1328 ms 284660 KB Output is correct
8 Correct 1219 ms 284788 KB Output is correct
9 Correct 1227 ms 284788 KB Output is correct
10 Correct 794 ms 108708 KB Output is correct
11 Correct 412 ms 90976 KB Output is correct
12 Correct 207 ms 7664 KB Output is correct
13 Correct 1519 ms 284716 KB Output is correct
14 Correct 1436 ms 285100 KB Output is correct
15 Correct 1282 ms 284660 KB Output is correct
16 Correct 499 ms 95732 KB Output is correct
17 Correct 1032 ms 114932 KB Output is correct
18 Correct 218 ms 8052 KB Output is correct
19 Correct 1565 ms 285144 KB Output is correct
20 Correct 1558 ms 284912 KB Output is correct
21 Correct 1754 ms 284868 KB Output is correct
22 Correct 835 ms 108896 KB Output is correct
23 Correct 398 ms 90868 KB Output is correct
24 Correct 200 ms 7668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4216 KB Output is correct
2 Correct 8 ms 4344 KB Output is correct
3 Correct 8 ms 4344 KB Output is correct
4 Correct 8 ms 4344 KB Output is correct
5 Correct 8 ms 4344 KB Output is correct
6 Correct 8 ms 4348 KB Output is correct
7 Correct 61 ms 29048 KB Output is correct
8 Correct 58 ms 29048 KB Output is correct
9 Correct 58 ms 29048 KB Output is correct
10 Correct 61 ms 33016 KB Output is correct
11 Correct 57 ms 26260 KB Output is correct
12 Correct 14 ms 4472 KB Output is correct
13 Correct 57 ms 29020 KB Output is correct
14 Correct 57 ms 29088 KB Output is correct
15 Correct 59 ms 29176 KB Output is correct
16 Correct 54 ms 26232 KB Output is correct
17 Correct 65 ms 35448 KB Output is correct
18 Correct 14 ms 4344 KB Output is correct
19 Correct 1355 ms 284872 KB Output is correct
20 Correct 1326 ms 285004 KB Output is correct
21 Correct 1421 ms 284876 KB Output is correct
22 Correct 404 ms 95604 KB Output is correct
23 Correct 972 ms 114764 KB Output is correct
24 Correct 218 ms 8052 KB Output is correct
25 Correct 1328 ms 284660 KB Output is correct
26 Correct 1219 ms 284788 KB Output is correct
27 Correct 1227 ms 284788 KB Output is correct
28 Correct 794 ms 108708 KB Output is correct
29 Correct 412 ms 90976 KB Output is correct
30 Correct 207 ms 7664 KB Output is correct
31 Correct 1519 ms 284716 KB Output is correct
32 Correct 1436 ms 285100 KB Output is correct
33 Correct 1282 ms 284660 KB Output is correct
34 Correct 499 ms 95732 KB Output is correct
35 Correct 1032 ms 114932 KB Output is correct
36 Correct 218 ms 8052 KB Output is correct
37 Correct 1565 ms 285144 KB Output is correct
38 Correct 1558 ms 284912 KB Output is correct
39 Correct 1754 ms 284868 KB Output is correct
40 Correct 835 ms 108896 KB Output is correct
41 Correct 398 ms 90868 KB Output is correct
42 Correct 200 ms 7668 KB Output is correct
43 Correct 1942 ms 637364 KB Output is correct
44 Correct 1904 ms 637172 KB Output is correct
45 Correct 1777 ms 637300 KB Output is correct
46 Correct 1722 ms 719292 KB Output is correct
47 Correct 1550 ms 456116 KB Output is correct
48 Correct 217 ms 8180 KB Output is correct
49 Correct 1946 ms 637556 KB Output is correct
50 Correct 1873 ms 637536 KB Output is correct
51 Correct 1877 ms 637556 KB Output is correct
52 Correct 1516 ms 456148 KB Output is correct
53 Correct 1735 ms 774712 KB Output is correct