結果

問題 No.1705 Mode of long array
ユーザー tnakao0123tnakao0123
提出日時 2021-10-09 03:42:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 3,000 ms
コード長 2,240 bytes
コンパイル時間 1,598 ms
コンパイル使用メモリ 93,284 KB
実行使用メモリ 7,832 KB
最終ジャッジ日時 2023-09-30 19:47:48
合計ジャッジ時間 5,917 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,720 KB
testcase_01 AC 5 ms
7,496 KB
testcase_02 AC 4 ms
7,724 KB
testcase_03 AC 5 ms
7,500 KB
testcase_04 AC 5 ms
7,832 KB
testcase_05 AC 5 ms
7,620 KB
testcase_06 AC 6 ms
7,652 KB
testcase_07 AC 7 ms
7,568 KB
testcase_08 AC 7 ms
7,624 KB
testcase_09 AC 6 ms
7,668 KB
testcase_10 AC 6 ms
7,556 KB
testcase_11 AC 6 ms
7,560 KB
testcase_12 AC 6 ms
7,584 KB
testcase_13 AC 45 ms
7,624 KB
testcase_14 AC 34 ms
7,640 KB
testcase_15 AC 35 ms
7,620 KB
testcase_16 AC 41 ms
7,576 KB
testcase_17 AC 30 ms
7,564 KB
testcase_18 AC 25 ms
7,628 KB
testcase_19 AC 45 ms
7,572 KB
testcase_20 AC 29 ms
7,564 KB
testcase_21 AC 37 ms
7,728 KB
testcase_22 AC 52 ms
7,572 KB
testcase_23 AC 36 ms
7,572 KB
testcase_24 AC 36 ms
7,660 KB
testcase_25 AC 36 ms
7,568 KB
testcase_26 AC 36 ms
7,716 KB
testcase_27 AC 36 ms
7,628 KB
testcase_28 AC 36 ms
7,660 KB
testcase_29 AC 36 ms
7,616 KB
testcase_30 AC 37 ms
7,708 KB
testcase_31 AC 36 ms
7,568 KB
testcase_32 AC 37 ms
7,756 KB
testcase_33 AC 58 ms
7,568 KB
testcase_34 AC 60 ms
7,572 KB
testcase_35 AC 58 ms
7,564 KB
testcase_36 AC 56 ms
7,616 KB
testcase_37 AC 56 ms
7,788 KB
testcase_38 AC 58 ms
7,716 KB
testcase_39 AC 60 ms
7,628 KB
testcase_40 AC 56 ms
7,496 KB
testcase_41 AC 58 ms
7,592 KB
testcase_42 AC 58 ms
7,496 KB
testcase_43 AC 46 ms
7,496 KB
testcase_44 AC 45 ms
7,496 KB
testcase_45 AC 46 ms
7,620 KB
testcase_46 AC 45 ms
7,496 KB
testcase_47 AC 46 ms
7,496 KB
testcase_48 AC 46 ms
7,660 KB
testcase_49 AC 58 ms
7,496 KB
testcase_50 AC 58 ms
7,500 KB
testcase_51 AC 58 ms
7,568 KB
testcase_52 AC 58 ms
7,572 KB
testcase_53 AC 58 ms
7,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1705.cc:  No.1705 Mode of long array - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_M = 100000;
const int MAX_E2 = 1 << 18; // = 262144

/* typedef */

typedef long long ll;
typedef pair<ll,int> pli;

template <typename T, const int MAX_E2>
struct SegTreeMax {
  int e2;
  T nodes[MAX_E2], defv;
  SegTreeMax() {}

  void init(int n, T _defv) {
    defv = _defv;
    for (e2 = 1; e2 < n; e2 <<= 1);
    fill(nodes, nodes + MAX_E2, defv);
  }

  T &geti(int i) { return nodes[e2 - 1 + i]; }
  void seti(int i, T v) { geti(i) = v; }

  void setall() {
    for (int j = e2 - 2; j >= 0; j--)
      nodes[j] = max(nodes[j * 2 + 1], nodes[j * 2 + 2]);
  }

  void set(int i, T v) {
    int j = e2 - 1 + i;
    nodes[j] = v;
    while (j > 0) {
      j = (j - 1) / 2;
      nodes[j] = max(nodes[j * 2 + 1], nodes[j * 2 + 2]);
    }
  }

  T max_range(int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return defv;
    if (r0 <= i0 && i1 <= r1) return nodes[k];

    int im = (i0 + i1) / 2;
    T v0 = max_range(r0, r1, k * 2 + 1, i0, im);
    T v1 = max_range(r0, r1, k * 2 + 2, im, i1);
    return max(v0, v1);
  }
  T max_range(int r0, int r1) { return max_range(r0, r1, 0, 0, e2); }
};

/* global variables */

SegTreeMax<pli,MAX_E2> st;

/* subroutines */

/* main */

int main() {
  ll n;
  int m;
  scanf("%lld%d", &n, &m);

  st.init(m, pli(0, -1));

  for (int i = 0; i < m; i++) {
    ll ai;
    scanf("%lld", &ai);
    st.seti(i, pli(ai, i));
  }
  st.setall();

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

  while (qn--) {
    int ti, xi;
    ll yi;
    scanf("%d%d%lld", &ti, &xi, &yi), xi--;

    if (ti == 1) {
      pli v = st.geti(xi);
      st.set(xi, pli(v.first + yi, v.second));
    }
    else if (ti == 2) {
      pli v = st.geti(xi);
      st.set(xi, pli(v.first - yi, v.second));
    }
    else printf("%d\n", st.nodes[0].second + 1);
  }
  return 0;
}
0