답안 #172737

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172737 2020-01-02T13:45:26 Z mhy908 Matryoshka (JOI16_matryoshka) C++14
51 / 100
115 ms 46264 KB
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const LL llinf=9000000000000000000;
const int inf=2000000000;
struct SEGMENT_TREE
{
    LL initial=-llinf;
    int x;
    struct NODE{
        int st, fin;
        LL q;
    }tree[800100];
    LL f(LL a, LL b){return max(a, b);}
    void init(int point, int num){
        if(num==1)tree[point].st=tree[point].fin=++x;
        if(num<=1)return;
        init(point*2, num-num/2);
        init(point*2+1, num/2);
        tree[point].st=tree[point*2].st;
        tree[point].fin=tree[point*2+1].fin;
    }
    void update(int point, int num, LL qu){
        if(tree[point].st==tree[point].fin){
            tree[point].q=qu;
            return;
        }
        if(num<=tree[point*2].fin)update(point*2, num, qu);
        else update(point*2+1, num, qu);
        tree[point].q=f(tree[point*2].q, tree[point*2+1].q);
    }
    LL query(int point, int a, int b){
        if(tree[point].st>=a&&tree[point].fin<=b)return tree[point].q;
        if(tree[point].st>b||tree[point].fin<a)return initial;
        return f(query(point*2, a, b), query(point*2+1, a, b));
    }
    void init(int num){init(1, num);}
    void update(int num, LL qu){update(1, num, qu);}
    LL query(int a, int b){return query(1, a, b);}
}seg;
int n, q;
pll point[200010], query[200010];
LL ans[200010];
vector<LL> idx;
vector<pair<pair<LL, int>, pair<LL, int>> > qu;
int main()
{
    scanf("%d %d", &n, &q);
    for(int i=1; i<=n; i++){
        scanf("%lld %lld", &point[i].F, &point[i].S);
        idx.pb(point[i].F);
        qu.pb(mp(mp(point[i].S, 1), mp(-point[i].F, 0)));
    }
    seg.init(n+q+10);
    for(int i=1; i<=q; i++){
        scanf("%lld %lld", &query[i].F, &query[i].S);
        idx.pb(query[i].F);
        qu.pb(mp(mp(query[i].S, 2), mp(query[i].F, i)));
    }
    sort(all(idx));
    sort(all(qu));
    for(auto Q:qu){
        if(Q.F.S==1){
            int temp=lower_bound(all(idx), -Q.S.F)-idx.begin()+1;
            seg.update(temp, seg.query(temp, n+q+10)+1);
        }
        else{
            int temp=lower_bound(all(idx), Q.S.F)-idx.begin()+1;
            ans[Q.S.S]=seg.query(temp, n+q+10);
        }
    }
    for(int i=1; i<=q; i++)printf("%lld\n", ans[i]);
}

Compilation message

matryoshka.cpp: In function 'int main()':
matryoshka.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~~
matryoshka.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld", &point[i].F, &point[i].S);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
matryoshka.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld", &query[i].F, &query[i].S);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 4 ms 632 KB Output is correct
23 Correct 6 ms 888 KB Output is correct
24 Correct 5 ms 888 KB Output is correct
25 Correct 6 ms 888 KB Output is correct
26 Correct 5 ms 888 KB Output is correct
27 Correct 5 ms 888 KB Output is correct
28 Correct 6 ms 928 KB Output is correct
29 Correct 5 ms 888 KB Output is correct
30 Correct 4 ms 888 KB Output is correct
31 Correct 6 ms 888 KB Output is correct
32 Correct 6 ms 888 KB Output is correct
33 Correct 6 ms 888 KB Output is correct
34 Correct 6 ms 888 KB Output is correct
35 Correct 6 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 4 ms 632 KB Output is correct
23 Correct 6 ms 888 KB Output is correct
24 Correct 5 ms 888 KB Output is correct
25 Correct 6 ms 888 KB Output is correct
26 Correct 5 ms 888 KB Output is correct
27 Correct 5 ms 888 KB Output is correct
28 Correct 6 ms 928 KB Output is correct
29 Correct 5 ms 888 KB Output is correct
30 Correct 4 ms 888 KB Output is correct
31 Correct 6 ms 888 KB Output is correct
32 Correct 6 ms 888 KB Output is correct
33 Correct 6 ms 888 KB Output is correct
34 Correct 6 ms 888 KB Output is correct
35 Correct 6 ms 888 KB Output is correct
36 Runtime error 115 ms 46264 KB Execution killed with signal 11 (could be triggered by violating memory limits)
37 Halted 0 ms 0 KB -