# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
92310 | maruii | Matryoshka (JOI16_matryoshka) | C++17 | 313 ms | 17212 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
#define ff first
#define ss second
const int SIZE = 1<<18;
struct ST{
int data[2*SIZE];
void update(int x, int v){
for(x+=SIZE; x; x/=2)
data[x] = max(data[x], v);
}
int query(int s, int e){
int ret = 0;
for(s+=SIZE, e+=SIZE; s<=e; s/=2, e/=2){
if(s&1) ret = max(ret, data[s++]);
if(~e&1) ret = max(ret, data[e--]);
}
return ret;
}
}seg;
ii p[200001];
pair<ii, int> qr[200001];
int ans[200001];
vector<int> xx,yy;
int main(){
int N,Q; scanf("%d%d",&N,&Q);
for(int i=0; i<N; ++i){
int x, y; scanf("%d%d",&x, &y);
p[i] = {-x, y};
xx.push_back(-x);
yy.push_back(y);
}
sort(xx.begin(), xx.end());
sort(yy.begin(), yy.end());
xx.erase(unique(xx.begin(), xx.end()), xx.end());
yy.erase(unique(yy.begin(), yy.end()), yy.end());
for(int i=0; i<N; ++i) p[i].ss = lower_bound(yy.begin(), yy.end(), p[i].ss) - yy.begin() + 1;
sort(p, p+N);
for(int i=0; i<Q; ++i){
int x, y; scanf("%d%d",&x,&y);
x = -x;
y = upper_bound(yy.begin(), yy.end(), y) - yy.begin();
qr[i] = {{x, y}, i};
}
sort(qr, qr+Q);
for(int i=0, j=0; i<Q; ++i){
while(j<N && p[j].ff<=qr[i].ff.ff){
seg.update(p[j].ss, seg.query(0, p[j].ss)+1);
++j;
}
ans[qr[i].ss] = seg.query(0, qr[i].ff.ss);
}
for(int i=0; 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... |