답안 #1029234

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1029234 2024-07-20T14:07:59 Z ihne Curtains (NOI23_curtains) C++17
9 / 100
1500 ms 44528 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=1e5+5;
const int mod=1e9+7;
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 (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>=1;i--){
    f[i]=1e9;
    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 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 5092 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4952 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 4 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 5092 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4952 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 4 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 16 ms 5212 KB Output is correct
14 Correct 17 ms 5212 KB Output is correct
15 Correct 16 ms 5212 KB Output is correct
16 Correct 16 ms 5212 KB Output is correct
17 Correct 17 ms 5388 KB Output is correct
18 Correct 22 ms 5208 KB Output is correct
19 Correct 15 ms 5208 KB Output is correct
20 Correct 10 ms 5464 KB Output is correct
21 Correct 14 ms 5464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 5092 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4952 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 4 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 16 ms 5212 KB Output is correct
14 Correct 17 ms 5212 KB Output is correct
15 Correct 16 ms 5212 KB Output is correct
16 Correct 16 ms 5212 KB Output is correct
17 Correct 17 ms 5388 KB Output is correct
18 Correct 22 ms 5208 KB Output is correct
19 Correct 15 ms 5208 KB Output is correct
20 Correct 10 ms 5464 KB Output is correct
21 Correct 14 ms 5464 KB Output is correct
22 Runtime error 75 ms 44396 KB Execution killed with signal 11
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 19 ms 5212 KB Output is correct
6 Correct 15 ms 5392 KB Output is correct
7 Correct 13 ms 5260 KB Output is correct
8 Runtime error 72 ms 44528 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 5092 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4952 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 4 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 16 ms 5212 KB Output is correct
14 Correct 17 ms 5212 KB Output is correct
15 Correct 16 ms 5212 KB Output is correct
16 Correct 16 ms 5212 KB Output is correct
17 Correct 17 ms 5388 KB Output is correct
18 Correct 22 ms 5208 KB Output is correct
19 Correct 15 ms 5208 KB Output is correct
20 Correct 10 ms 5464 KB Output is correct
21 Correct 14 ms 5464 KB Output is correct
22 Execution timed out 1578 ms 12744 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 5092 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4952 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 4 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 16 ms 5212 KB Output is correct
14 Correct 17 ms 5212 KB Output is correct
15 Correct 16 ms 5212 KB Output is correct
16 Correct 16 ms 5212 KB Output is correct
17 Correct 17 ms 5388 KB Output is correct
18 Correct 22 ms 5208 KB Output is correct
19 Correct 15 ms 5208 KB Output is correct
20 Correct 10 ms 5464 KB Output is correct
21 Correct 14 ms 5464 KB Output is correct
22 Runtime error 75 ms 44396 KB Execution killed with signal 11
23 Halted 0 ms 0 KB -