# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
172756 | songc | Matryoshka (JOI16_matryoshka) | C++14 | 321 ms | 12268 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int N, Q;
int T[202020];
int ans[202020];
pii A[202020];
vector<int> comp, L;
struct query{
int a, b, id;
bool operator<(const query &r)const{
return a > r.a;
}
} qu[202020];
void update(int k, int v){
while (k<=N){
T[k] = max(T[k], v);
k += k&-k;
}
}
int read(int k){
int ret=0;
while (k>0){
ret = max(ret, T[k]);
k ^= k&-k;
}
return ret;
}
int com(int k){return lower_bound(comp.begin(), comp.end(), k)-comp.begin()+1;}
int main(){
scanf("%d %d", &N, &Q);
for (int i=1; i<=N; i++){
scanf("%d %d", &A[i].first, &A[i].second);
comp.push_back(A[i].second);
}
sort(comp.begin(), comp.end());
comp.erase(unique(comp.begin(), comp.end()), comp.end());
sort(A+1, A+N+1, [&](pii a, pii b){
if (a.first == b.first) return a.second < b.second;
return a.first > b.first;
});
for (int i=1; i<=Q; i++){
scanf("%d %d", &qu[i].a, &qu[i].b);
qu[i].id = i;
}
sort(qu+1, qu+Q+1);
int t=1;
for (int i=1; i<=Q; i++){
while (A[t].first >= qu[i].a){
int lis = upper_bound(L.begin(), L.end(), A[t].second)-L.begin()+1;
if (lis > L.size()) L.push_back(A[t].second);
else L[lis-1] = A[t].second;
update(com(A[t].second), lis);
t++;
}
int k = com(qu[i].b+1)-1;
ans[qu[i].id] = read(k);
}
for (int i=1; i<=Q; i++) printf("%d\n", ans[i]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |