답안 #1029247

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1029247 2024-07-20T14:16:13 Z ihne Curtains (NOI23_curtains) C++17
100 / 100
486 ms 101156 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
const int mn=5e5+5;
struct query{
  int l,r,id;
};
int a[mn],ans[mn],f[mn];
vector<int> L[mn],R[mn];
void solve(int l,int r,vector<query> q){
  if (q.empty()) return;
  if (l==r){
    int bl=0;
    for (int j:L[l]) if (j==r) bl=1;
    for (int i=0;i<q.size();i++){
      ans[q[i].id]=bl;
    }
    return;
  }
  int mid=l+r>>1;
  stack<int> v;
  for (int i=mid;i>=l;i--){
    f[i]=1000000000;
    for (int j:L[i]){
      if (j>=mid) f[i]=min(f[i],j);
      while (!v.empty()&&v.top()-1<=j&&j<=f[v.top()]){
        f[i]=min(f[i],f[v.top()]);
        v.pop();
      }
    }
    v.push(i);
  }
  while (!v.empty()) v.pop();
  for (int i=mid+1;i<=r;i++){
    f[i]=0;
    for (int j:R[i]){
      if (j<=mid+1) f[i]=max(f[i],j);
      while (!v.empty()&&v.top()+1>=j&&j>=f[v.top()]){
        f[i]=max(f[i],f[v.top()]);
        v.pop();
      }
    }
    v.push(i);
  }
  vector<query> vl,vr;
  for (int i=0;i<q.size();i++){
    if (q[i].r<=mid) vl.pb(q[i]);
    else if (q[i].l>mid) vr.pb(q[i]);
    else{
      if (f[q[i].l]<=q[i].r&&f[q[i].r]>=q[i].l) ans[q[i].id]=1;
    }
  }
  solve(l,mid,vl);
  solve(mid+1,r,vr);
}
signed main(){
  //freopen("","r",stdin);
  //freopen("","w",stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n,m,Q;
  cin>>n>>m>>Q;
  for (int i=1;i<=m;i++){
    int l,r;
    cin>>l>>r;
    L[l].pb(r);
    R[r].pb(l);
  }
  vector<query> q;
  for (int i=1;i<=Q;i++){
    int l,r;
    cin>>l>>r;
    q.pb({l,r,i});
  }
  solve(1,n,q);
  for (int i=1;i<=Q;i++){
    if (ans[i]) cout<<"YES\n";
    else cout<<"NO\n";
  }
}

Compilation message

curtains.cpp: In function 'void solve(int, int, std::vector<query>)':
curtains.cpp:18:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int i=0;i<q.size();i++){
      |                  ~^~~~~~~~~
curtains.cpp:23:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   23 |   int mid=l+r>>1;
      |           ~^~
curtains.cpp:49:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |   for (int i=0;i<q.size();i++){
      |                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23896 KB Output is correct
2 Correct 10 ms 23912 KB Output is correct
3 Correct 12 ms 23900 KB Output is correct
4 Correct 10 ms 23896 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 9 ms 23888 KB Output is correct
7 Correct 10 ms 23900 KB Output is correct
8 Correct 11 ms 23900 KB Output is correct
9 Correct 9 ms 23980 KB Output is correct
10 Correct 11 ms 23900 KB Output is correct
11 Correct 10 ms 23940 KB Output is correct
12 Correct 12 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23896 KB Output is correct
2 Correct 10 ms 23912 KB Output is correct
3 Correct 12 ms 23900 KB Output is correct
4 Correct 10 ms 23896 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 9 ms 23888 KB Output is correct
7 Correct 10 ms 23900 KB Output is correct
8 Correct 11 ms 23900 KB Output is correct
9 Correct 9 ms 23980 KB Output is correct
10 Correct 11 ms 23900 KB Output is correct
11 Correct 10 ms 23940 KB Output is correct
12 Correct 12 ms 23900 KB Output is correct
13 Correct 11 ms 23952 KB Output is correct
14 Correct 11 ms 24048 KB Output is correct
15 Correct 12 ms 24152 KB Output is correct
16 Correct 13 ms 24156 KB Output is correct
17 Correct 11 ms 24152 KB Output is correct
18 Correct 12 ms 23956 KB Output is correct
19 Correct 12 ms 23960 KB Output is correct
20 Correct 13 ms 24140 KB Output is correct
21 Correct 12 ms 24196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23896 KB Output is correct
2 Correct 10 ms 23912 KB Output is correct
3 Correct 12 ms 23900 KB Output is correct
4 Correct 10 ms 23896 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 9 ms 23888 KB Output is correct
7 Correct 10 ms 23900 KB Output is correct
8 Correct 11 ms 23900 KB Output is correct
9 Correct 9 ms 23980 KB Output is correct
10 Correct 11 ms 23900 KB Output is correct
11 Correct 10 ms 23940 KB Output is correct
12 Correct 12 ms 23900 KB Output is correct
13 Correct 11 ms 23952 KB Output is correct
14 Correct 11 ms 24048 KB Output is correct
15 Correct 12 ms 24152 KB Output is correct
16 Correct 13 ms 24156 KB Output is correct
17 Correct 11 ms 24152 KB Output is correct
18 Correct 12 ms 23956 KB Output is correct
19 Correct 12 ms 23960 KB Output is correct
20 Correct 13 ms 24140 KB Output is correct
21 Correct 12 ms 24196 KB Output is correct
22 Correct 112 ms 47700 KB Output is correct
23 Correct 106 ms 47424 KB Output is correct
24 Correct 123 ms 49336 KB Output is correct
25 Correct 157 ms 56760 KB Output is correct
26 Correct 105 ms 48056 KB Output is correct
27 Correct 149 ms 58664 KB Output is correct
28 Correct 156 ms 58712 KB Output is correct
29 Correct 91 ms 61364 KB Output is correct
30 Correct 82 ms 52660 KB Output is correct
31 Correct 81 ms 53656 KB Output is correct
32 Correct 135 ms 63144 KB Output is correct
33 Correct 90 ms 52968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 23900 KB Output is correct
2 Correct 10 ms 23900 KB Output is correct
3 Correct 13 ms 23900 KB Output is correct
4 Correct 10 ms 23980 KB Output is correct
5 Correct 11 ms 24152 KB Output is correct
6 Correct 11 ms 24156 KB Output is correct
7 Correct 10 ms 24176 KB Output is correct
8 Correct 77 ms 52308 KB Output is correct
9 Correct 84 ms 53172 KB Output is correct
10 Correct 132 ms 61924 KB Output is correct
11 Correct 75 ms 52736 KB Output is correct
12 Correct 53 ms 35268 KB Output is correct
13 Correct 52 ms 35024 KB Output is correct
14 Correct 51 ms 35012 KB Output is correct
15 Correct 57 ms 34508 KB Output is correct
16 Correct 52 ms 34760 KB Output is correct
17 Correct 49 ms 34500 KB Output is correct
18 Correct 290 ms 80104 KB Output is correct
19 Correct 325 ms 80284 KB Output is correct
20 Correct 333 ms 80816 KB Output is correct
21 Correct 356 ms 79148 KB Output is correct
22 Correct 298 ms 78264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23896 KB Output is correct
2 Correct 10 ms 23912 KB Output is correct
3 Correct 12 ms 23900 KB Output is correct
4 Correct 10 ms 23896 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 9 ms 23888 KB Output is correct
7 Correct 10 ms 23900 KB Output is correct
8 Correct 11 ms 23900 KB Output is correct
9 Correct 9 ms 23980 KB Output is correct
10 Correct 11 ms 23900 KB Output is correct
11 Correct 10 ms 23940 KB Output is correct
12 Correct 12 ms 23900 KB Output is correct
13 Correct 11 ms 23952 KB Output is correct
14 Correct 11 ms 24048 KB Output is correct
15 Correct 12 ms 24152 KB Output is correct
16 Correct 13 ms 24156 KB Output is correct
17 Correct 11 ms 24152 KB Output is correct
18 Correct 12 ms 23956 KB Output is correct
19 Correct 12 ms 23960 KB Output is correct
20 Correct 13 ms 24140 KB Output is correct
21 Correct 12 ms 24196 KB Output is correct
22 Correct 44 ms 31696 KB Output is correct
23 Correct 73 ms 31436 KB Output is correct
24 Correct 98 ms 34244 KB Output is correct
25 Correct 77 ms 34244 KB Output is correct
26 Correct 66 ms 38476 KB Output is correct
27 Correct 82 ms 38796 KB Output is correct
28 Correct 64 ms 35012 KB Output is correct
29 Correct 72 ms 37484 KB Output is correct
30 Correct 71 ms 34292 KB Output is correct
31 Correct 80 ms 34272 KB Output is correct
32 Correct 100 ms 35980 KB Output is correct
33 Correct 128 ms 36920 KB Output is correct
34 Correct 71 ms 37860 KB Output is correct
35 Correct 52 ms 35784 KB Output is correct
36 Correct 56 ms 35560 KB Output is correct
37 Correct 54 ms 34900 KB Output is correct
38 Correct 70 ms 34932 KB Output is correct
39 Correct 70 ms 35016 KB Output is correct
40 Correct 52 ms 34576 KB Output is correct
41 Correct 75 ms 34760 KB Output is correct
42 Correct 62 ms 34368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23896 KB Output is correct
2 Correct 10 ms 23912 KB Output is correct
3 Correct 12 ms 23900 KB Output is correct
4 Correct 10 ms 23896 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 9 ms 23888 KB Output is correct
7 Correct 10 ms 23900 KB Output is correct
8 Correct 11 ms 23900 KB Output is correct
9 Correct 9 ms 23980 KB Output is correct
10 Correct 11 ms 23900 KB Output is correct
11 Correct 10 ms 23940 KB Output is correct
12 Correct 12 ms 23900 KB Output is correct
13 Correct 11 ms 23952 KB Output is correct
14 Correct 11 ms 24048 KB Output is correct
15 Correct 12 ms 24152 KB Output is correct
16 Correct 13 ms 24156 KB Output is correct
17 Correct 11 ms 24152 KB Output is correct
18 Correct 12 ms 23956 KB Output is correct
19 Correct 12 ms 23960 KB Output is correct
20 Correct 13 ms 24140 KB Output is correct
21 Correct 12 ms 24196 KB Output is correct
22 Correct 112 ms 47700 KB Output is correct
23 Correct 106 ms 47424 KB Output is correct
24 Correct 123 ms 49336 KB Output is correct
25 Correct 157 ms 56760 KB Output is correct
26 Correct 105 ms 48056 KB Output is correct
27 Correct 149 ms 58664 KB Output is correct
28 Correct 156 ms 58712 KB Output is correct
29 Correct 91 ms 61364 KB Output is correct
30 Correct 82 ms 52660 KB Output is correct
31 Correct 81 ms 53656 KB Output is correct
32 Correct 135 ms 63144 KB Output is correct
33 Correct 90 ms 52968 KB Output is correct
34 Correct 9 ms 23900 KB Output is correct
35 Correct 10 ms 23900 KB Output is correct
36 Correct 13 ms 23900 KB Output is correct
37 Correct 10 ms 23980 KB Output is correct
38 Correct 11 ms 24152 KB Output is correct
39 Correct 11 ms 24156 KB Output is correct
40 Correct 10 ms 24176 KB Output is correct
41 Correct 77 ms 52308 KB Output is correct
42 Correct 84 ms 53172 KB Output is correct
43 Correct 132 ms 61924 KB Output is correct
44 Correct 75 ms 52736 KB Output is correct
45 Correct 53 ms 35268 KB Output is correct
46 Correct 52 ms 35024 KB Output is correct
47 Correct 51 ms 35012 KB Output is correct
48 Correct 57 ms 34508 KB Output is correct
49 Correct 52 ms 34760 KB Output is correct
50 Correct 49 ms 34500 KB Output is correct
51 Correct 290 ms 80104 KB Output is correct
52 Correct 325 ms 80284 KB Output is correct
53 Correct 333 ms 80816 KB Output is correct
54 Correct 356 ms 79148 KB Output is correct
55 Correct 298 ms 78264 KB Output is correct
56 Correct 44 ms 31696 KB Output is correct
57 Correct 73 ms 31436 KB Output is correct
58 Correct 98 ms 34244 KB Output is correct
59 Correct 77 ms 34244 KB Output is correct
60 Correct 66 ms 38476 KB Output is correct
61 Correct 82 ms 38796 KB Output is correct
62 Correct 64 ms 35012 KB Output is correct
63 Correct 72 ms 37484 KB Output is correct
64 Correct 71 ms 34292 KB Output is correct
65 Correct 80 ms 34272 KB Output is correct
66 Correct 100 ms 35980 KB Output is correct
67 Correct 128 ms 36920 KB Output is correct
68 Correct 71 ms 37860 KB Output is correct
69 Correct 52 ms 35784 KB Output is correct
70 Correct 56 ms 35560 KB Output is correct
71 Correct 54 ms 34900 KB Output is correct
72 Correct 70 ms 34932 KB Output is correct
73 Correct 70 ms 35016 KB Output is correct
74 Correct 52 ms 34576 KB Output is correct
75 Correct 75 ms 34760 KB Output is correct
76 Correct 62 ms 34368 KB Output is correct
77 Correct 441 ms 76832 KB Output is correct
78 Correct 447 ms 76976 KB Output is correct
79 Correct 369 ms 98992 KB Output is correct
80 Correct 419 ms 99244 KB Output is correct
81 Correct 361 ms 95412 KB Output is correct
82 Correct 355 ms 97724 KB Output is correct
83 Correct 349 ms 76720 KB Output is correct
84 Correct 356 ms 76696 KB Output is correct
85 Correct 486 ms 86624 KB Output is correct
86 Correct 279 ms 101156 KB Output is correct
87 Correct 261 ms 87060 KB Output is correct
88 Correct 321 ms 86452 KB Output is correct