Submission #207673

# Submission time Handle Problem Language Result Execution time Memory
207673 2020-03-08T14:01:31 Z nvmdava Examination (JOI19_examination) C++17
2 / 100
3000 ms 190980 KB
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define ff first
#define ss second
#define N 100005
#define MOD 1000000007
#define INF 0x3f3f3f3f

vector<pair<int, pair<int, int> > > ar;
vector<pair<pair<int, int>, pair<int, int> > > qu;
map<int, int> scmp, tcmp;

map<int, int> bit[N];

int get(int x, int y){
    int s = 0;
    while(x){
        int t = y;
        while(t){
            auto it = bit[x].find(t);
            if(it != bit[x].end())
                s += it -> ss;
            t -= t & -t;
        }
        x -= x & -x;
    }
    return s;
}

void update(int x, int y){
    while(x < N){
        int t = y;
        while(t < N){
            ++bit[x][t];
            t += t & -t;
        }
        x += x & -x;
    }
}

int ans[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n, q;
    cin>>n>>q;
    int mxs = 0, mxt = 0;
    for(int i = 1; i <= n; ++i){
        int s, t;
        cin>>s>>t;
        mxs = max(mxs, s);
        mxt = max(mxt, t);
        ar.push_back({s + t, {s, t}});
        scmp[s] = 0;
        tcmp[t] = 0;
    }
    int w;

    w = 0;
    for(auto& x : scmp)
        x.ss = ++w;
    w = 0;
    for(auto& x : tcmp)
        x.ss = ++w;
    int ss = scmp.size(), ts = tcmp.size();
    for(auto& x : ar){
        x.ss.ff = ss + 1 - scmp[x.ss.ff];
        x.ss.ss = ts + 1 - tcmp[x.ss.ss];
    }

    sort(ar.rbegin(), ar.rend());

    for(int i = 1; i <= q; ++i){
        int a, b, c;
        cin>>a>>b>>c;
        if(a > mxs || b > mxt)
            continue;
        a = scmp.lower_bound(a) -> ss;
        b = tcmp.lower_bound(b) -> ss;
        a = ss + 1 - a;
        b = ts + 1 - b;
        qu.push_back({{c, i}, {a, b}});
    }
    sort(qu.rbegin(), qu.rend());

    w = 0;

    for(auto& x : qu){
        while(w != n && ar[w].ff >= x.ff.ff){
            update(ar[w].ss.ff, ar[w].ss.ss);
            ++w;
        }
        ans[x.ff.ss] = get(x.ss.ff, x.ss.ss);
    }
    for(int i = 1; i <= q; ++i)
        cout<<ans[i]<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5112 KB Output is correct
2 Correct 8 ms 5112 KB Output is correct
3 Correct 8 ms 5112 KB Output is correct
4 Correct 7 ms 5112 KB Output is correct
5 Correct 8 ms 4984 KB Output is correct
6 Correct 8 ms 5112 KB Output is correct
7 Correct 46 ms 10232 KB Output is correct
8 Correct 47 ms 10232 KB Output is correct
9 Correct 48 ms 10232 KB Output is correct
10 Correct 25 ms 7804 KB Output is correct
11 Correct 39 ms 7804 KB Output is correct
12 Correct 17 ms 5240 KB Output is correct
13 Correct 48 ms 10232 KB Output is correct
14 Correct 51 ms 10232 KB Output is correct
15 Correct 50 ms 10312 KB Output is correct
16 Correct 36 ms 7800 KB Output is correct
17 Correct 21 ms 7800 KB Output is correct
18 Correct 16 ms 5240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3092 ms 190980 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3092 ms 190980 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5112 KB Output is correct
2 Correct 8 ms 5112 KB Output is correct
3 Correct 8 ms 5112 KB Output is correct
4 Correct 7 ms 5112 KB Output is correct
5 Correct 8 ms 4984 KB Output is correct
6 Correct 8 ms 5112 KB Output is correct
7 Correct 46 ms 10232 KB Output is correct
8 Correct 47 ms 10232 KB Output is correct
9 Correct 48 ms 10232 KB Output is correct
10 Correct 25 ms 7804 KB Output is correct
11 Correct 39 ms 7804 KB Output is correct
12 Correct 17 ms 5240 KB Output is correct
13 Correct 48 ms 10232 KB Output is correct
14 Correct 51 ms 10232 KB Output is correct
15 Correct 50 ms 10312 KB Output is correct
16 Correct 36 ms 7800 KB Output is correct
17 Correct 21 ms 7800 KB Output is correct
18 Correct 16 ms 5240 KB Output is correct
19 Execution timed out 3092 ms 190980 KB Time limit exceeded
20 Halted 0 ms 0 KB -