답안 #753706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
753706 2023-06-05T18:02:25 Z epicci23 Alternating Heights (CCO22_day1problem1) C++17
25 / 25
337 ms 13896 KB
#include "bits/stdc++.h"
#pragma optimize ("Bismillahirrahmanirrahim")
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define endl "\n" 
#define int long long
#define double long double
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define what_is(x) cerr << #x << " is " << x << endl;
//#define m (l+r)/2
constexpr int N=200005;
constexpr int MOD=1000000007;
constexpr int  INF2 = LLONG_MAX;
constexpr int INF=(int)1e18;
constexpr int LOG=30;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tp;
typedef priority_queue<pii,vector<pii>,greater<pii>> min_pq;
typedef priority_queue<pii> max_pq;
typedef long long ll;
//to think//
/*
 * graph approach
 * dp
 * dividing the problem to smaller statements
 * finding the real constraint
 * sqrt decomposition
 * greedy approach
 * pigeonhole principle
 * rewriting the problem/equality 
 * bitwise approaches
 * binary search if monotonic
 * divide and conquer
 * combinatorics
 * inclusion - exclusion
 * think like bfs
*/



inline int in()
{
  int x;cin >> x;
  return x;
}

inline string in2()
{
  string x;cin >> x;
  return x;
}


vector<int> v[3003];
int col[3003];
bool ok=0;
int ar[3003];

void dfs(int c)
{
  if(ok) return;
  if(col[c]==1) {ok=1;return;}
  if(col[c]==2) return;
  col[c]=1;
  for(int x:v[c]) dfs(x);
  col[c]=2;
}

bool check(int l,int r)
{
  ok=0;
  for(int i=0;i<=3000;i++)
  {
    v[i].clear();
    col[i]=0;
  }

  for(int i=l;i<r;i++)
  {
    if((i-l)&1) v[ar[i+1]].pb(ar[i]);
    else v[ar[i]].pb(ar[i+1]);
  }
  
  for(int i=1;i<=3000;i++) dfs(i);
  return ok;
}


void solve()
{
  int n=in(),k=in(),q=in();
  
  for(int i=1;i<=n;i++) ar[i]=in();
  ar[n+1]=0;
  int xd[n+2];
  
  int p=1;

  for(int i=1;i<=n;i++)
  {
    while(p<=n && !check(i,p)) p++;
    xd[i]=p;
  }

  for(int i=1;i<=q;i++)
  {
    int u=in(),r=in();
    if(xd[u]<=r) cout << "NO\n";
    else cout << "YES\n";
  }
}

int32_t main(){
   

     cin.tie(0); ios::sync_with_stdio(0);
     cout << fixed <<  setprecision(15);
   
   int t=1;//cin>> t;
 
 for(int i=1;i<=t;i++)
 {
  //  cout << "Case #" << i << ": ";
    solve();
 }
 
 return 0;
}

Compilation message

Main.cpp:2: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    2 | #pragma optimize ("Bismillahirrahmanirrahim")
      | 
Main.cpp: In function 'void solve()':
Main.cpp:95:14: warning: unused variable 'k' [-Wunused-variable]
   95 |   int n=in(),k=in(),q=in();
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 240 ms 3380 KB Output is correct
2 Correct 223 ms 3572 KB Output is correct
3 Correct 227 ms 3420 KB Output is correct
4 Correct 117 ms 3324 KB Output is correct
5 Correct 142 ms 3584 KB Output is correct
6 Correct 227 ms 3392 KB Output is correct
7 Correct 217 ms 3400 KB Output is correct
8 Correct 225 ms 3392 KB Output is correct
9 Correct 230 ms 3536 KB Output is correct
10 Correct 258 ms 4024 KB Output is correct
11 Correct 237 ms 4684 KB Output is correct
12 Correct 311 ms 4424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 166 ms 3380 KB Output is correct
2 Correct 157 ms 3452 KB Output is correct
3 Correct 165 ms 3440 KB Output is correct
4 Correct 128 ms 4332 KB Output is correct
5 Correct 135 ms 3532 KB Output is correct
6 Correct 154 ms 3404 KB Output is correct
7 Correct 175 ms 3428 KB Output is correct
8 Correct 178 ms 3496 KB Output is correct
9 Correct 168 ms 3852 KB Output is correct
10 Correct 188 ms 4408 KB Output is correct
11 Correct 146 ms 4388 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 112 ms 472 KB Output is correct
3 Correct 122 ms 492 KB Output is correct
4 Correct 64 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 106 ms 476 KB Output is correct
8 Correct 128 ms 592 KB Output is correct
9 Correct 169 ms 496 KB Output is correct
10 Correct 132 ms 496 KB Output is correct
11 Correct 139 ms 492 KB Output is correct
12 Correct 116 ms 696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 240 ms 3380 KB Output is correct
2 Correct 223 ms 3572 KB Output is correct
3 Correct 227 ms 3420 KB Output is correct
4 Correct 117 ms 3324 KB Output is correct
5 Correct 142 ms 3584 KB Output is correct
6 Correct 227 ms 3392 KB Output is correct
7 Correct 217 ms 3400 KB Output is correct
8 Correct 225 ms 3392 KB Output is correct
9 Correct 230 ms 3536 KB Output is correct
10 Correct 258 ms 4024 KB Output is correct
11 Correct 237 ms 4684 KB Output is correct
12 Correct 311 ms 4424 KB Output is correct
13 Correct 166 ms 3380 KB Output is correct
14 Correct 157 ms 3452 KB Output is correct
15 Correct 165 ms 3440 KB Output is correct
16 Correct 128 ms 4332 KB Output is correct
17 Correct 135 ms 3532 KB Output is correct
18 Correct 154 ms 3404 KB Output is correct
19 Correct 175 ms 3428 KB Output is correct
20 Correct 178 ms 3496 KB Output is correct
21 Correct 168 ms 3852 KB Output is correct
22 Correct 188 ms 4408 KB Output is correct
23 Correct 146 ms 4388 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 112 ms 472 KB Output is correct
27 Correct 122 ms 492 KB Output is correct
28 Correct 64 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 106 ms 476 KB Output is correct
32 Correct 128 ms 592 KB Output is correct
33 Correct 169 ms 496 KB Output is correct
34 Correct 132 ms 496 KB Output is correct
35 Correct 139 ms 492 KB Output is correct
36 Correct 116 ms 696 KB Output is correct
37 Correct 325 ms 13420 KB Output is correct
38 Correct 307 ms 13268 KB Output is correct
39 Correct 226 ms 12748 KB Output is correct
40 Correct 118 ms 8264 KB Output is correct
41 Correct 139 ms 9776 KB Output is correct
42 Correct 270 ms 13396 KB Output is correct
43 Correct 337 ms 13688 KB Output is correct
44 Correct 305 ms 13468 KB Output is correct
45 Correct 302 ms 13896 KB Output is correct
46 Correct 283 ms 13788 KB Output is correct
47 Correct 311 ms 13760 KB Output is correct