답안 #172769

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172769 2020-01-02T15:02:34 Z arnold518 Matryoshka (JOI16_matryoshka) C++14
51 / 100
262 ms 8032 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2e5;

struct Point
{
    int x, y, p;
};

int N, Q, ans[MAXN+10];
Point A[MAXN+10];
vector<int> xcomp, ycomp;

int tree[MAXN*2+10];
void update(int i, int val) { for(; i<=xcomp.size(); i+=(i&-i)) tree[i]=max(tree[i], val); }
int query(int i) { int ret=0; for(; i>0; i-=(i&-i)) ret=max(ret, tree[i]); return ret; }

int main()
{
    int i, j;

    scanf("%d%d", &N, &Q);
    for(i=1; i<=N; i++)
    {
        scanf("%d%d", &A[i].x, &A[i].y);
        A[i].x*=-1; A[i].p=-1;
        xcomp.push_back(A[i].x);
        ycomp.push_back(A[i].y);
    }

    for(i=N+1; i<=N+Q; i++)
    {
        scanf("%d%d", &A[i].x, &A[i].y);
        A[i].x*=-1; A[i].p=i-N;
        xcomp.push_back(A[i].x);
        ycomp.push_back(A[i].y);
    }

    sort(xcomp.begin(), xcomp.end());
    sort(ycomp.begin(), ycomp.end());
    xcomp.erase(unique(xcomp.begin(), xcomp.end()), xcomp.end());
    ycomp.erase(unique(ycomp.begin(), ycomp.end()), ycomp.end());

    for(i=1; i<=N+Q; i++) A[i].x=lower_bound(xcomp.begin(), xcomp.end(), A[i].x)-xcomp.begin()+1;
    for(i=1; i<=N+Q; i++) A[i].y=lower_bound(ycomp.begin(), ycomp.end(), A[i].y)-ycomp.begin()+1;

    sort(A+1, A+N+Q+1, [&](const Point &p, const Point &q)
         {
             if(pii(p.y, p.x)!=pii(q.y, q.x)) return pii(p.y, p.x)<pii(q.y, q.x);
             else return p.p<q.p;
         });

    for(i=1; i<=N+Q; i++)
    {
        if(A[i].p==-1) update(A[i].x, query(A[i].x)+1);
        else ans[A[i].p]=query(A[i].x);
    }
    for(i=1; i<=Q; i++) printf("%d\n", ans[i]);
}

Compilation message

matryoshka.cpp: In function 'void update(int, int)':
matryoshka.cpp:20:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 void update(int i, int val) { for(; i<=xcomp.size(); i+=(i&-i)) tree[i]=max(tree[i], val); }
                                     ~^~~~~~~~~~~~~~
matryoshka.cpp: In function 'int main()':
matryoshka.cpp:25:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
matryoshka.cpp:27: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:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &A[i].x, &A[i].y);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
matryoshka.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &A[i].x, &A[i].y);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 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 1 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 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 1 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 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 380 KB Output is correct
20 Correct 3 ms 420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 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 1 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 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 380 KB Output is correct
20 Correct 3 ms 420 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 4 ms 376 KB Output is correct
23 Correct 6 ms 504 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 6 ms 504 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 552 KB Output is correct
28 Correct 5 ms 504 KB Output is correct
29 Correct 11 ms 504 KB Output is correct
30 Correct 4 ms 504 KB Output is correct
31 Correct 6 ms 504 KB Output is correct
32 Correct 6 ms 504 KB Output is correct
33 Correct 6 ms 504 KB Output is correct
34 Correct 5 ms 500 KB Output is correct
35 Correct 6 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 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 1 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 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 380 KB Output is correct
20 Correct 3 ms 420 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 4 ms 376 KB Output is correct
23 Correct 6 ms 504 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 6 ms 504 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 552 KB Output is correct
28 Correct 5 ms 504 KB Output is correct
29 Correct 11 ms 504 KB Output is correct
30 Correct 4 ms 504 KB Output is correct
31 Correct 6 ms 504 KB Output is correct
32 Correct 6 ms 504 KB Output is correct
33 Correct 6 ms 504 KB Output is correct
34 Correct 5 ms 500 KB Output is correct
35 Correct 6 ms 632 KB Output is correct
36 Incorrect 262 ms 8032 KB Output isn't correct
37 Halted 0 ms 0 KB -