Submission #36605482


Source Code Expand

const long long MOD = 998244353;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef complex<double> cd;

#define forn(i, n) for (int i = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << " fine, thanks" << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Yes[2] = {"No\n", "Yes\n"};
string YES[2] = {"NO\n", "YES\n"};
string Possible[2] = {"Impossible\n", "Possible\n"};
string POSSIBLE[2] = {"IMPOSSIBLE\n", "POSSIBLE\n"};

#define ok(x, n) (0 <= (x) && (x) < (n))
#define withBit(mask, i) ((mask & (1 << i)) > 0)

ll binpow(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = binpow(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

#define inq binpow

ll rev(ll x)
{
    return binpow(x, MOD - 2);
}

int _comb_precomputed_combinatorics = 0;
vector<ll> _comb_fact, _comb_ufact, _comb_rev;

inline void _comb_precompute_combinatorics(int _comb_n)
{
    if (_comb_n < 2) _comb_n = 2;
    if (_comb_precomputed_combinatorics >= _comb_n)
        return;
    _comb_fact.resize(_comb_n);
    _comb_ufact.resize(_comb_n);
    _comb_rev.resize(_comb_n);
    _comb_rev[1] = 1;
    for (int i = max(2, _comb_precomputed_combinatorics); i < _comb_n; i++)
        _comb_rev[i] = MOD - _comb_rev[MOD % i] * (MOD / i) % MOD;
    _comb_fact[0] = 1, _comb_ufact[0] = 1;
    for (int i = max(1, _comb_precomputed_combinatorics); i < _comb_n; i++)
        _comb_fact[i] = _comb_fact[i - 1] * i % MOD, _comb_ufact[i] = _comb_ufact[i - 1] * _comb_rev[i] % MOD;
    _comb_precomputed_combinatorics = _comb_n;
}

ll fact(int x)
{
    if (_comb_precomputed_combinatorics <= x)
        _comb_precompute_combinatorics(x + 1);
    return _comb_fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n)
        return 0;
    if (_comb_precomputed_combinatorics <= n)
        _comb_precompute_combinatorics(n + 1);
    return _comb_fact[n] * _comb_ufact[n - k] % MOD * _comb_ufact[k] % MOD;
}

template<typename T> istream& operator>>(istream& in, vector<T>& a)
{
    for (int i = 0; i < a.size(); i++)
        in >> a[i];
    return in;
}

template<typename T> ostream& operator<<(ostream& out, const vector<T>& a)
{
    for (auto e : a)
    {
        out << e << " ";
        if (typeid(T) != typeid(int) && typeid(T) != typeid(ll))
            out << "\n";
    }
    return out;
}

void solve()
{
    int n;
    cin >> n;
    vll a(n);
    cin >> a;
    int q;
    cin >> q;
    ll lst_mass = -2, val = 0;
    vll lst(n, -1);
    for (int i = 0; i < q; i++)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int x;
            cin >> x;
            lst_mass = i;
            val = x;
        }
        if (t == 2)
        {
            int j, x;
            cin >> j >> x;
            j--;
            ll cur = 0;
            if (lst_mass > lst[j])
                cur = val;
            else
                cur = a[j];
            cur += x;
            lst[j] = i;
            a[j] = cur;
        }
        if (t == 3)
        {
            int j;
            cin >> j;
            j--;
            if (lst_mass > lst[j])
                cout << val << "\n";
            else
                cout << a[j] << "\n";
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    #ifdef tests
    cin >> t;
    #endif // tests
    while (t--)
    {
        solve();
    }
}

Submission Info

Submission Time
Task D - All Assign Point Add
User IgorI
Language C++ (GCC 9.2.1)
Score 400
Code Size 4221 Byte
Status AC
Exec Time 67 ms
Memory 6352 KiB

Compile Error

./Main.cpp: In instantiation of ‘std::istream& operator>>(std::istream&, std::vector<_Tp>&) [with T = long long int; std::istream = std::basic_istream<char>]’:
./Main.cpp:120:12:   required from here
./Main.cpp:99:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   99 |     for (int i = 0; i < a.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 6 ms 3568 KiB
00_sample_01.txt AC 2 ms 3428 KiB
00_sample_02.txt AC 2 ms 3508 KiB
01_N_small_03.txt AC 43 ms 3600 KiB
01_N_small_04.txt AC 37 ms 3596 KiB
01_N_small_05.txt AC 42 ms 3600 KiB
01_N_small_06.txt AC 41 ms 3552 KiB
02_random_07.txt AC 46 ms 4720 KiB
02_random_08.txt AC 47 ms 5716 KiB
02_random_09.txt AC 41 ms 4552 KiB
02_random_10.txt AC 50 ms 5296 KiB
03_max_11.txt AC 67 ms 6244 KiB
04_handmade_12.txt AC 52 ms 4692 KiB
04_handmade_13.txt AC 46 ms 3824 KiB
04_handmade_14.txt AC 58 ms 6352 KiB