Submission #126916

# Submission time Handle Problem Language Result Execution time Memory
126916 2019-07-08T15:37:26 Z zoooma13 Examination (JOI19_examination) C++14
22 / 100
3000 ms 37496 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
#define all(v) (v).begin() ,(v).end()

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);
    merge(all(stree[FL]) ,all(stree[FR]) ,back_inserter(stree[p]));
}
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:70: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:72: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:90: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 16760 KB Output is correct
2 Correct 17 ms 16760 KB Output is correct
3 Correct 16 ms 16760 KB Output is correct
4 Correct 17 ms 16760 KB Output is correct
5 Correct 17 ms 16760 KB Output is correct
6 Correct 22 ms 16764 KB Output is correct
7 Correct 29 ms 17532 KB Output is correct
8 Correct 30 ms 17528 KB Output is correct
9 Correct 29 ms 17400 KB Output is correct
10 Correct 28 ms 17404 KB Output is correct
11 Correct 32 ms 17232 KB Output is correct
12 Correct 23 ms 17016 KB Output is correct
13 Correct 26 ms 17528 KB Output is correct
14 Correct 26 ms 17400 KB Output is correct
15 Correct 26 ms 17400 KB Output is correct
16 Correct 22 ms 17144 KB Output is correct
17 Correct 25 ms 17272 KB Output is correct
18 Correct 20 ms 17016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 410 ms 37444 KB Output is correct
2 Correct 407 ms 37332 KB Output is correct
3 Correct 417 ms 37408 KB Output is correct
4 Correct 342 ms 36024 KB Output is correct
5 Correct 232 ms 30484 KB Output is correct
6 Correct 124 ms 25724 KB Output is correct
7 Correct 409 ms 37316 KB Output is correct
8 Correct 367 ms 37428 KB Output is correct
9 Correct 378 ms 37496 KB Output is correct
10 Correct 192 ms 29688 KB Output is correct
11 Correct 273 ms 35224 KB Output is correct
12 Correct 84 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 410 ms 37444 KB Output is correct
2 Correct 407 ms 37332 KB Output is correct
3 Correct 417 ms 37408 KB Output is correct
4 Correct 342 ms 36024 KB Output is correct
5 Correct 232 ms 30484 KB Output is correct
6 Correct 124 ms 25724 KB Output is correct
7 Correct 409 ms 37316 KB Output is correct
8 Correct 367 ms 37428 KB Output is correct
9 Correct 378 ms 37496 KB Output is correct
10 Correct 192 ms 29688 KB Output is correct
11 Correct 273 ms 35224 KB Output is correct
12 Correct 84 ms 23764 KB Output is correct
13 Execution timed out 3041 ms 36724 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 16760 KB Output is correct
2 Correct 17 ms 16760 KB Output is correct
3 Correct 16 ms 16760 KB Output is correct
4 Correct 17 ms 16760 KB Output is correct
5 Correct 17 ms 16760 KB Output is correct
6 Correct 22 ms 16764 KB Output is correct
7 Correct 29 ms 17532 KB Output is correct
8 Correct 30 ms 17528 KB Output is correct
9 Correct 29 ms 17400 KB Output is correct
10 Correct 28 ms 17404 KB Output is correct
11 Correct 32 ms 17232 KB Output is correct
12 Correct 23 ms 17016 KB Output is correct
13 Correct 26 ms 17528 KB Output is correct
14 Correct 26 ms 17400 KB Output is correct
15 Correct 26 ms 17400 KB Output is correct
16 Correct 22 ms 17144 KB Output is correct
17 Correct 25 ms 17272 KB Output is correct
18 Correct 20 ms 17016 KB Output is correct
19 Correct 410 ms 37444 KB Output is correct
20 Correct 407 ms 37332 KB Output is correct
21 Correct 417 ms 37408 KB Output is correct
22 Correct 342 ms 36024 KB Output is correct
23 Correct 232 ms 30484 KB Output is correct
24 Correct 124 ms 25724 KB Output is correct
25 Correct 409 ms 37316 KB Output is correct
26 Correct 367 ms 37428 KB Output is correct
27 Correct 378 ms 37496 KB Output is correct
28 Correct 192 ms 29688 KB Output is correct
29 Correct 273 ms 35224 KB Output is correct
30 Correct 84 ms 23764 KB Output is correct
31 Execution timed out 3041 ms 36724 KB Time limit exceeded
32 Halted 0 ms 0 KB -