답안 #1109635

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1109635 2024-11-07T08:12:08 Z cpptowin XORanges (eJOI19_xoranges) C++17
100 / 100
114 ms 20864 KB
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf (int)1e18
#define bitcount(x) __builtin_popcountll(x)
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define ss(x) (int)x.size()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
void add(int &x, int k)
{
    x += k;
    x %= mod;
    if(x < 0) x += mod;
}
void del(int &x, int k)
{
    x -= k;
    x %= mod;
    if(x < 0) x += mod;
}
struct SegmentTree
{
    vector<int> st;
    int n;
    /// real n
    SegmentTree(int _n = 0) : n(_n)
    {
        st.resize(4 * n + 10);
    }
    void resize(int _n)
    {
        n = _n;
        st.resize(4 * n + 10);
    }
    void assign(int id, int l, int r, int x, int val)
    {
        if (x > r or x < l)
            return;
        if (l == r)
        {
            st[id] = val;
            return;
        }
        int mid = (l + r) >> 1;
        assign(id << 1, l, mid, x, val);
        assign(id << 1 | 1, mid + 1, r, x, val);
        st[id] = st[id << 1] ^ st[id << 1 | 1];
    }
    int get(int id, int l, int r, int u, int v)
    {
        if (l > v || u > r)
            return 0;
        if (u <= l && r <= v)
            return st[id];
        int mid = (l + r) >> 1;
        return get(id << 1, l, mid, u, v) ^ get(id << 1 | 1, mid + 1, r, u, v);
    }
    int get(int l, int r)
    {
        return get(1, 1, n, l, r);
    }
    void assign(int x, int val)
    {
        assign(1, 1, n, x, val);
    }
}t[2];
int n,a[maxn],q;
main()
{
#define name "TASK"
    if (fopen(name ".inp", "r"))
    {
        freopen(name ".inp", "r", stdin);
        freopen(name ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> q;
    t[0].resize(n);
    t[1].resize(n);
    fo(i,1,n)
    {
        cin >> a[i];
        t[i & 1].assign(i,a[i]);
    }
    while(q--)
    {
        int ty;
        cin >> ty;
        if(ty == 1)
        {
            int x,val;
            cin >> x >> val;
            t[x & 1].assign(x,val);
        }
        else
        {
            int l,r;
            cin >> l >> r;
            if(l % 2 == r % 2)
                cout << t[l % 2].get(l,r) << "\n";
            else cout << 0 << "\n";
        }
    }
}

Compilation message

xoranges.cpp:105:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  105 | main()
      | ^~~~
xoranges.cpp: In function 'int main()':
xoranges.cpp:110:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  110 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
xoranges.cpp:111:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 504 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 3 ms 848 KB Output is correct
12 Correct 5 ms 848 KB Output is correct
13 Correct 4 ms 740 KB Output is correct
14 Correct 3 ms 848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 16456 KB Output is correct
2 Correct 109 ms 20040 KB Output is correct
3 Correct 114 ms 20228 KB Output is correct
4 Correct 90 ms 20040 KB Output is correct
5 Correct 85 ms 16208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 504 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 3 ms 848 KB Output is correct
12 Correct 5 ms 848 KB Output is correct
13 Correct 4 ms 740 KB Output is correct
14 Correct 3 ms 848 KB Output is correct
15 Correct 93 ms 16456 KB Output is correct
16 Correct 109 ms 20040 KB Output is correct
17 Correct 114 ms 20228 KB Output is correct
18 Correct 90 ms 20040 KB Output is correct
19 Correct 85 ms 16208 KB Output is correct
20 Correct 94 ms 15724 KB Output is correct
21 Correct 97 ms 20864 KB Output is correct
22 Correct 98 ms 20040 KB Output is correct
23 Correct 89 ms 20808 KB Output is correct
24 Correct 102 ms 20808 KB Output is correct