Submission #36638715


Source Code Expand

#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
typedef  long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
using namespace std;
template <typename T>
struct RMQ {
    const T INF = numeric_limits<T>::max();
    int n;
    vector<T> dat, lazy;
    RMQ(int n_) : n(), dat(n_ * 4, -1), lazy(n_ * 4, -1) {
        int x = 1;
        while (n_ > x) x *= 2;
        n = x;
    }
    /* lazy eval */
    void eval(int k) {
        if (lazy[k] == 0) return;  // 更新するものが無ければ終了
        if (k < n - 1) {             // 葉でなければ子に伝搬
            lazy[k * 2] = lazy[k];
            lazy[k * 2 + 1] = lazy[k];
        }
        // 自身を更新
        dat[k] = lazy[k];
        lazy[k] = 0;
    }
    void update(int a, int b, T x, int k, int l, int r) {
        eval(k);
        if (a <= l && r <= b) {  // 完全に内側の時
            lazy[k] = x;
            eval(k);
        }
        else if (a < r && l < b) {                     // 一部区間が被る時
            update(a, b, x, k * 2, l, (l + r) / 2);  // 左の子
            update(a, b, x, k * 2 + 1, (l + r) / 2, r);  // 右の子
            dat[k] = max(dat[k * 2], dat[k * 2 + 1]);
        }
    }
    void update(int a, int b, T x) { update(a, b, x, 1, 0, n); }
    T query_sub(int a, int b, int k, int l, int r) {
        eval(k);
        if (r <= a || b <= l) {  // 完全に外側の時
            return 0;
        }
        else if (a <= l && r <= b) {  // 完全に内側の時
            return dat[k];
        }
        else {  // 一部区間が被る時
            T vl = query_sub(a, b, k * 2, l, (l + r) / 2);
            T vr = query_sub(a, b, k * 2 + 1, (l + r) / 2, r);
            return max(vl, vr);
        }
    }
    T query(int a, int b) { return query_sub(a, b, 1, 0, n); }
    /* debug */
    inline T operator[](int a) { return query(a, a + 1); }
    void print() {
        for (int i = 0; i < 2 * n - 1; ++i) {
            cout << (*this)[i];
            if (i != n) cout << ",";
        }
        cout << endl;
    }
};

int main() {
    int n, q;
    cin >> n;
    vector<ll>ans;
    RMQ<ll> seg(n + 1);
    for (int i = 1; i <= n; i++) {
        int a;
        cin >> a;
        seg.update(i - 1, i, a);
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if (t == 1) {
            int x;
            cin >> x;
            seg.update(0, n+1, x);
        }
        else if (t == 2) {
            int iq, xq;
            cin >> iq >> xq;
            seg.update(iq - 1, iq, xq+seg.query(iq-1,iq));
        }
        else{
            int x;
            cin >> x;
            ans.push_back(seg.query(x - 1, x));
        }
    }
    for (int i = 0; i < ans.size(); i++) {
        cout<<ans[i] <<endl;
    }
    return 0;
}

Submission Info

Submission Time
Task D - All Assign Point Add
User amaoto
Language C++ (GCC 9.2.1)
Score 400
Code Size 2947 Byte
Status AC
Exec Time 384 ms
Memory 16656 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:98:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   98 |     for (int i = 0; i < ans.size(); i++) {
      |                     ~~^~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 15
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_N_small_03.txt, 01_N_small_04.txt, 01_N_small_05.txt, 01_N_small_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 03_max_11.txt, 04_handmade_12.txt, 04_handmade_13.txt, 04_handmade_14.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 7 ms 3456 KiB
00_sample_01.txt AC 2 ms 3656 KiB
00_sample_02.txt AC 2 ms 3528 KiB
01_N_small_03.txt AC 181 ms 4268 KiB
01_N_small_04.txt AC 108 ms 3732 KiB
01_N_small_05.txt AC 127 ms 3680 KiB
01_N_small_06.txt AC 301 ms 5208 KiB
02_random_07.txt AC 242 ms 10000 KiB
02_random_08.txt AC 201 ms 13472 KiB
02_random_09.txt AC 171 ms 9832 KiB
02_random_10.txt AC 364 ms 13608 KiB
03_max_11.txt AC 384 ms 16656 KiB
04_handmade_12.txt AC 320 ms 10412 KiB
04_handmade_13.txt AC 284 ms 7312 KiB
04_handmade_14.txt AC 355 ms 16624 KiB