結果

問題 No.1705 Mode of long array
コンテスト
ユーザー siman
提出日時 2022-11-12 01:09:50
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 150 ms / 3,000 ms
コード長 1,558 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,418 ms
コンパイル使用メモリ 150,400 KB
実行使用メモリ 10,852 KB
最終ジャッジ日時 2026-04-04 06:50:22
合計ジャッジ時間 13,126 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 51
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:43:18: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   43 |   int time_table[M + 1];
      |                  ^~~~~
main.cpp:43:18: note: read of non-const variable 'M' is not allowed in a constant expression
main.cpp:39:9: note: declared here
   39 |   ll N, M;
      |         ^
main.cpp:44:14: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   44 |   ll counter[M + 1];
      |              ^~~~~
main.cpp:44:14: note: read of non-const variable 'M' is not allowed in a constant expression
main.cpp:39:9: note: declared here
   39 |   ll N, M;
      |         ^
2 warnings generated.

ソースコード

diff #
raw source code

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

struct Node {
  int x;
  ll cnt;
  int updated_at;

  Node(int x = -1, ll cnt = -1, int updated_at = -1) {
    this->x = x;
    this->cnt = cnt;
    this->updated_at = updated_at;
  }

  bool operator>(const Node &n) const {
    if (cnt == n.cnt) {
      return x < n.x;
    } else {
      return cnt < n.cnt;
    }
  }
};

int main() {
  ll N, M;
  cin >> N >> M;
  priority_queue <Node, vector<Node>, greater<Node>> pque;

  int time_table[M + 1];
  ll counter[M + 1];
  memset(time_table, 0, sizeof(time_table));
  for (int i = 1; i <= M; ++i) {
    ll a;
    cin >> a;
    counter[i] = a;
    pque.push(Node(i, a, 0));
  }

  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    int t, x;
    ll y;
    cin >> t >> x >> y;

    // fprintf(stderr, "t: %d, x: %d, y: %lld\n", t, x, y);
    if (t == 1) {
      counter[x] += y;
      time_table[x]++;
      pque.push(Node(x, counter[x], time_table[x]));
    } else if (t == 2) {
      counter[x] -= y;
      time_table[x]++;
      pque.push(Node(x, counter[x], time_table[x]));
    } else {
      while (true) {
        Node node = pque.top();

        if (node.updated_at < time_table[node.x]) {
          pque.pop();
        } else {
          break;
        }
      }

      cout << pque.top().x << endl;
    }
  }

  return 0;
}
0