Submission #126913

# Submission time Handle Problem Language Result Execution time Memory
126913 2019-07-08T15:34:05 Z zoooma13 Examination (JOI19_examination) C++14
22 / 100
3000 ms 39864 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MAX_N 100005
#define FL (p<<1)|1
#define FR (p<<1)+2

struct cont{
    int a ,b ,c ,idx;
    bool operator<(const cont&rhs){
        return c < rhs.c;
    }
};

vector <int> comp;
int smlr(int num){
    return lower_bound(comp.begin() ,comp.end() ,num)-comp.begin();
}

int n ,q;
vector <cont> stds;
vector <cont> qs;
vector <int> pnts[3*MAX_N];

vector <int> stree[4*MAX_N];
void bld(int l=0 ,int r=comp.size() ,int p=0)
{
    if(l == r){
        for(int&v : pnts[l])
            stree[p].push_back(v);
        sort(stree[p].begin() ,stree[p].end());
        return;
    }

    int mid = (l+r)>>1;
    bld(l ,mid ,FL);
    bld(mid+1 ,r ,FR);
    for(auto&v : stree[FL])
        stree[p].push_back(v);
    for(auto&v : stree[FR])
        stree[p].push_back(v);
    sort(stree[p].begin() ,stree[p].end());
}
int qry(int ql ,int v ,int l=0 ,int r=comp.size() ,int p=0)
{
    if(ql <= l)
        return stree[p].size()-(lower_bound(stree[p].begin() ,stree[p].end() ,v)-stree[p].begin());
    if(r < ql)
        return 0;

    int mid = (l+r)>>1;
    return qry(ql ,v ,l ,mid ,FL) + qry(ql ,v ,mid+1 ,r ,FR);
}
void rem(int id ,int va ,int l=0 ,int r=comp.size() ,int p=0)
{
    stree[p].erase(find(stree[p].begin() ,stree[p].end() ,va));
    if(l == r)
        return;

    int mid = (l+r)>>1;
    if(id <= mid) rem(id ,va ,l ,mid ,FL);
    else          rem(id ,va ,mid+1 ,r ,FR);
}

int main()
{
    scanf("%d%d",&n,&q);
    for(int s,t,i=0; i<n; i++){
        scanf("%d%d",&s,&t);
        stds.push_back({s ,t ,s+t ,i});
        comp.push_back(s);
        comp.push_back(t);
        comp.push_back(s+t);
    }

    sort(comp.begin() ,comp.end());
    comp.resize(unique(comp.begin() ,comp.end())-comp.begin());

    for(auto&s : stds){
        s.a = smlr(s.a);
        s.b = smlr(s.b);
        s.c = smlr(s.c);
        pnts[s.a].push_back(s.b);
    }

    for(int a,b,c,i=0; i<q; i++){
        scanf("%d%d%d",&a,&b,&c);
        a = smlr(a);
        b = smlr(b);
        c = smlr(c);
        qs.push_back({a ,b ,c ,i});
    }

    sort(stds.begin() ,stds.end());
    sort(qs.begin() ,qs.end());

    bld();

    vector <int> ans(q);
    int st_ptr = 0;
    for(cont&q : qs){
        while(st_ptr < n && stds[st_ptr].c < q.c){
            rem(stds[st_ptr].a ,stds[st_ptr].b);
            st_ptr++;
        }

        ans[q.idx] = qry(q.a ,q.b);
    }

    for(int&i : ans)
        printf("%d\n",i);
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&q);
     ~~~~~^~~~~~~~~~~~~~
examination.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&s,&t);
         ~~~~~^~~~~~~~~~~~~~
examination.cpp:93:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&a,&b,&c);
         ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 16732 KB Output is correct
2 Correct 18 ms 16732 KB Output is correct
3 Correct 18 ms 16780 KB Output is correct
4 Correct 17 ms 16732 KB Output is correct
5 Correct 17 ms 16732 KB Output is correct
6 Correct 18 ms 16760 KB Output is correct
7 Correct 32 ms 17656 KB Output is correct
8 Correct 30 ms 17528 KB Output is correct
9 Correct 31 ms 17732 KB Output is correct
10 Correct 29 ms 17528 KB Output is correct
11 Correct 34 ms 17276 KB Output is correct
12 Correct 24 ms 17124 KB Output is correct
13 Correct 27 ms 17656 KB Output is correct
14 Correct 28 ms 17552 KB Output is correct
15 Correct 27 ms 17528 KB Output is correct
16 Correct 23 ms 17144 KB Output is correct
17 Correct 26 ms 17400 KB Output is correct
18 Correct 21 ms 16944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 491 ms 39852 KB Output is correct
2 Correct 467 ms 39864 KB Output is correct
3 Correct 483 ms 39796 KB Output is correct
4 Correct 364 ms 37716 KB Output is correct
5 Correct 276 ms 32268 KB Output is correct
6 Correct 131 ms 26640 KB Output is correct
7 Correct 453 ms 39848 KB Output is correct
8 Correct 439 ms 39760 KB Output is correct
9 Correct 413 ms 39632 KB Output is correct
10 Correct 222 ms 31196 KB Output is correct
11 Correct 297 ms 36944 KB Output is correct
12 Correct 88 ms 24656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 491 ms 39852 KB Output is correct
2 Correct 467 ms 39864 KB Output is correct
3 Correct 483 ms 39796 KB Output is correct
4 Correct 364 ms 37716 KB Output is correct
5 Correct 276 ms 32268 KB Output is correct
6 Correct 131 ms 26640 KB Output is correct
7 Correct 453 ms 39848 KB Output is correct
8 Correct 439 ms 39760 KB Output is correct
9 Correct 413 ms 39632 KB Output is correct
10 Correct 222 ms 31196 KB Output is correct
11 Correct 297 ms 36944 KB Output is correct
12 Correct 88 ms 24656 KB Output is correct
13 Execution timed out 3027 ms 39704 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 16732 KB Output is correct
2 Correct 18 ms 16732 KB Output is correct
3 Correct 18 ms 16780 KB Output is correct
4 Correct 17 ms 16732 KB Output is correct
5 Correct 17 ms 16732 KB Output is correct
6 Correct 18 ms 16760 KB Output is correct
7 Correct 32 ms 17656 KB Output is correct
8 Correct 30 ms 17528 KB Output is correct
9 Correct 31 ms 17732 KB Output is correct
10 Correct 29 ms 17528 KB Output is correct
11 Correct 34 ms 17276 KB Output is correct
12 Correct 24 ms 17124 KB Output is correct
13 Correct 27 ms 17656 KB Output is correct
14 Correct 28 ms 17552 KB Output is correct
15 Correct 27 ms 17528 KB Output is correct
16 Correct 23 ms 17144 KB Output is correct
17 Correct 26 ms 17400 KB Output is correct
18 Correct 21 ms 16944 KB Output is correct
19 Correct 491 ms 39852 KB Output is correct
20 Correct 467 ms 39864 KB Output is correct
21 Correct 483 ms 39796 KB Output is correct
22 Correct 364 ms 37716 KB Output is correct
23 Correct 276 ms 32268 KB Output is correct
24 Correct 131 ms 26640 KB Output is correct
25 Correct 453 ms 39848 KB Output is correct
26 Correct 439 ms 39760 KB Output is correct
27 Correct 413 ms 39632 KB Output is correct
28 Correct 222 ms 31196 KB Output is correct
29 Correct 297 ms 36944 KB Output is correct
30 Correct 88 ms 24656 KB Output is correct
31 Execution timed out 3027 ms 39704 KB Time limit exceeded
32 Halted 0 ms 0 KB -