結果

問題 No.3198 Monotonic Query
ユーザー tnakao0123
提出日時 2025-07-12 10:34:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 745 bytes
コンパイル時間 907 ms
コンパイル使用メモリ 58,868 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2025-07-12 10:34:50
合計ジャッジ時間 3,375 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 WA * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |   scanf("%d", &qn);
      |   ~~~~~^~~~~~~~~~~
main.cpp:37:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |     scanf("%d%d", &op, &x);
      |     ~~~~~^~~~~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 3198.cc:  No.3198 Monotonic Query - yukicoder
 */

#include<cstdio>
#include<deque>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

using dqi = deque<int>;

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

int main() {
  int qn;
  scanf("%d", &qn);

  int n = 0;
  dqi q;
  
  while (qn--) {
    int op, x;
    scanf("%d%d", &op, &x);

    if (op == 1) {
      while (! q.empty() && as[q.back()] <= x) q.pop_back();
      q.push_back(n);
      as[n++] = x;
    }
    else {
      while (! q.empty() && n - q.front() > x) q.pop_front();
      int maxa = ! q.empty() ? as[q.front()] : 0;
      printf("%d\n", maxa);
    }
  }

  return 0;
}
0