結果

問題 No.1705 Mode of long array
ユーザー hayatenhayaten
提出日時 2021-10-09 13:47:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 3,000 ms
コード長 3,674 bytes
コンパイル時間 5,828 ms
コンパイル使用メモリ 309,356 KB
実行使用メモリ 12,972 KB
最終ジャッジ日時 2023-10-09 22:29:58
合計ジャッジ時間 11,862 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 3 ms
4,372 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 5 ms
4,372 KB
testcase_08 AC 4 ms
4,372 KB
testcase_09 AC 5 ms
4,372 KB
testcase_10 AC 4 ms
4,372 KB
testcase_11 AC 5 ms
4,372 KB
testcase_12 AC 4 ms
4,372 KB
testcase_13 AC 60 ms
10,520 KB
testcase_14 AC 43 ms
7,944 KB
testcase_15 AC 39 ms
7,140 KB
testcase_16 AC 49 ms
7,552 KB
testcase_17 AC 37 ms
7,020 KB
testcase_18 AC 28 ms
5,928 KB
testcase_19 AC 55 ms
8,360 KB
testcase_20 AC 34 ms
6,652 KB
testcase_21 AC 45 ms
9,456 KB
testcase_22 AC 67 ms
11,412 KB
testcase_23 AC 38 ms
7,104 KB
testcase_24 AC 39 ms
8,036 KB
testcase_25 AC 38 ms
7,192 KB
testcase_26 AC 37 ms
7,808 KB
testcase_27 AC 36 ms
7,544 KB
testcase_28 AC 39 ms
7,128 KB
testcase_29 AC 37 ms
7,304 KB
testcase_30 AC 37 ms
7,272 KB
testcase_31 AC 37 ms
7,040 KB
testcase_32 AC 37 ms
7,132 KB
testcase_33 AC 84 ms
12,356 KB
testcase_34 AC 86 ms
11,992 KB
testcase_35 AC 82 ms
12,232 KB
testcase_36 AC 80 ms
12,428 KB
testcase_37 AC 80 ms
12,324 KB
testcase_38 AC 81 ms
12,320 KB
testcase_39 AC 79 ms
12,416 KB
testcase_40 AC 80 ms
12,196 KB
testcase_41 AC 85 ms
12,436 KB
testcase_42 AC 84 ms
12,252 KB
testcase_43 AC 53 ms
12,304 KB
testcase_44 AC 59 ms
12,180 KB
testcase_45 AC 58 ms
12,160 KB
testcase_46 AC 58 ms
12,368 KB
testcase_47 AC 59 ms
12,700 KB
testcase_48 AC 65 ms
12,888 KB
testcase_49 AC 75 ms
12,192 KB
testcase_50 AC 75 ms
12,372 KB
testcase_51 AC 77 ms
12,160 KB
testcase_52 AC 74 ms
12,372 KB
testcase_53 AC 76 ms
12,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region Macros
// #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <atcoder/all>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define overload4(_1,_2,_3,_4,name,...) name
#define overload3(_1,_2,_3,name,...) name
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i=n;i--;)
#define rrep2(i,n) for(ll i=n;i--;)
#define rrep3(i,a,b) for(ll i=b;i-->(a);)
#define rrep4(i,a,b,c) for(ll i=(a)+((b)-(a)-1)/(c)*(c);i>=(a);i-=c)
#define rrep(...) overload4(__VA_ARGS__,rrep4,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define fi first
#define se second
#define popcount(bit) __builtin_popcount(bit)
#define popcountll(bit) __builtin_popcountll(bit)
#define pb push_back
#define eb emplace_back
#define sz(x) ((ll)(x).size())
using namespace atcoder;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Graph = vector<vector<int>>;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
inline void Yes(bool b = true) { cout << (b ? "Yes" : "No") << '\n'; }
inline void YES(bool b = true) { cout << (b ? "YES" : "NO") << '\n'; }
inline void OKNG(bool b = true) { cout << (b ? "OK" : "NG") << '\n'; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int fx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int fy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
template <typename T>
const auto INF = numeric_limits<T>::max()/2;

template <typename T>
vector<T> compress(vector<T> &X) {
  // ソートした結果を vals に
  vector<T> vals = X;
  sort(vals.begin(), vals.end());
  // 隣り合う重複を削除(unique), 末端のゴミを削除(erase)
  vals.erase(unique(vals.begin(), vals.end()), vals.end());
  // 各要素ごとに二分探索で位置を求める
  for (int i = 0; i < (int)X.size(); i++) {
    X[i] = lower_bound(vals.begin(), vals.end(), X[i]) - vals.begin();
  }
  return vals;
}

ll op(ll a, ll b){
  return max(a, b);
}

ll e(){
  return -1;
}

ll target = -1;
bool f(ll v){
  return v < target;
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> A(m);
  vector<ll> tmp(m);
  rep(i, m){
    cin >> A[i];
    tmp[i] = i + 1;
  }
  int q;
  cin >> q;
  vector<tuple<ll, ll, ll>> query;
  rep(i, q){
    ll t, x, y;
    cin >> t >> x >> y;
    tmp.pb(x);
    query.pb(make_tuple(t, x, y));
  }
  vector<ll> res = compress(tmp);
  vector<ll> rest(res.size());
  rep(i, m){
    rest[tmp[i]] = A[i];
  }
  segtree<ll, op, e> seg(rest);
  int g = res.size();
  rep(i, q){
    auto [a, b, c] = query[i];
    if(a == 1){
      ll d = tmp[m + i];
      ll h = seg.get(d);
      h += c;
      seg.set(d, h);
    }else if(a == 2){
      ll d = tmp[m+ i];
      ll h = seg.get(d);
      h -= c;
      seg.set(d, h);
    }else{
      target = seg.all_prod();
      cout << res[seg.min_left<f>(g) - 1] << endl;
    }
  }
}
0