結果

問題 No.905 Sorted?
ユーザー LayCurseLayCurse
提出日時 2019-10-11 21:45:16
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 2,331 bytes
コンパイル時間 2,273 ms
コンパイル使用メモリ 209,452 KB
実行使用メモリ 4,968 KB
最終ジャッジ日時 2023-08-16 17:31:45
合計ジャッジ時間 3,916 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 7 ms
4,380 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 8 ms
4,792 KB
testcase_11 AC 5 ms
4,632 KB
testcase_12 AC 7 ms
4,520 KB
testcase_13 AC 9 ms
4,896 KB
testcase_14 AC 10 ms
4,880 KB
testcase_15 AC 6 ms
4,956 KB
testcase_16 AC 6 ms
4,900 KB
testcase_17 AC 6 ms
4,904 KB
testcase_18 AC 5 ms
4,968 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd_int(void){
  int x;
  rd(x);
  return x;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int L;
int R;
long long A[100000];
int up[100000];
int dw[100000];
int main(){
  int KL2GvlyY, i;
  int res1;
  int res2;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  up[N-1] = dw[N-1] = N-1;
  for(i=(N-1)-1;i>=(0);i--){
    if(A[i+1] >= A[i]){
      up[i] =up[i+1];
    }
    else{
      up[i] =i;
    }
    if(A[i+1] <= A[i]){
      dw[i] =dw[i+1];
    }
    else{
      dw[i] =i;
    }
  }
  int Q5VJL1cS = rd_int();
  for(KL2GvlyY=(0);KL2GvlyY<(Q5VJL1cS);KL2GvlyY++){
    rd(L);
    rd(R);
    if(up[L] >= R){
      res1 =1;
    }
    else{
      res1 =0;
    }
    if(dw[L] >= R){
      res2 =1;
    }
    else{
      res2 =0;
    }
    wt_L(res1);
    wt_L(' ');
    wt_L(res2);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20191006-1

// --- original code ---
// int N, L, R; ll A[1d5];
// int up[1d5], dw[1d5];
// {
//   int res1, res2;
//   rd(N,A(N));
//   up[N-1] = dw[N-1] = N-1;
//   rrep(i,N-1){
//     up[i] = if[A[i+1] >= A[i], up[i+1], i];
//     dw[i] = if[A[i+1] <= A[i], dw[i+1], i];
//   }
//   REP(rd_int()){
//     rd(L,R);
//     res1 = if[up[L] >= R, 1, 0];
//     res2 = if[dw[L] >= R, 1, 0];
//     wt(res1,res2);
//   }
// }
0