답안 #444114

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
444114 2021-07-13T06:24:58 Z idas XORanges (eJOI19_xoranges) C++17
100 / 100
137 ms 12564 KB
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(long long i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define SZ(x) ((int)((x).size()))
#define LE(vec) vec[vec.size()-1]
#define TSTS int t; cin >> t; while(t--)solve()

const int INF = 1e9;
const long long LINF = 1e18;
const long double PI = asin(1)*2;
const int MOD = 1e9+7;

using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef long long ll;
typedef long double ld;

void setIO()
{
    FAST_IO;
}

void setIO (string s) {
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
 	freopen((s+".out").c_str(),"w",stdout);
}

const int N=2e5+10;
int n, q; ll to[2*N], te[2*N];

void build()
{
    for(int i=n-1; i>0; i--){
        to[i]=to[i<<1]^to[i<<1|1];
        te[i]=te[i<<1]^te[i<<1|1];
    }
}

void upd(int p, int x)
{
    if(p&1){
        for(to[p+=n]=x; p>1; p>>=1) to[p>>1]=to[p]^to[p^1];
    }
    else{
        for(te[p+=n]=x; p>1; p>>=1) te[p>>1]=te[p]^te[p^1];
    }
}

int ans(int l, int r)
{
    int ret=0;
    if((r-l)&1){
        if(l&1){
            for(l+=n, r+=n; l<r; l>>=1, r>>=1){
                if(l&1) ret^=to[l++];
                if(r&1) ret^=to[--r];
            }
        }
        else{
            for(l+=n, r+=n; l<r; l>>=1, r>>=1){
                if(l&1) ret^=te[l++];
                if(r&1) ret^=te[--r];
            }
        }
    }
    return ret;
}

int main()
{
    setIO();
    cin >> n >> q;
    FOR(i, 0, n)
    {
        if(i&1) cin >> to[i+n];
        else cin >> te[i+n];
    }
    build();
    FOR(i, 0, q)
    {
        int in;
        cin >> in;
        if(in&1){
            int p, x;
            cin >> p >> x;
            upd(p-1, x);
        }
        else{
            int l, r;
            cin >> l >> r;
            cout << ans(l-1, r) << '\n';
        }
    }
}

Compilation message

xoranges.cpp: In function 'void setIO(std::string)':
xoranges.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   freopen((s+".in").c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xoranges.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   freopen((s+".out").c_str(),"w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 4 ms 592 KB Output is correct
12 Correct 3 ms 588 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
14 Correct 4 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 128 ms 7644 KB Output is correct
2 Correct 133 ms 12564 KB Output is correct
3 Correct 130 ms 12532 KB Output is correct
4 Correct 117 ms 12216 KB Output is correct
5 Correct 121 ms 12212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 4 ms 592 KB Output is correct
12 Correct 3 ms 588 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
14 Correct 4 ms 596 KB Output is correct
15 Correct 128 ms 7644 KB Output is correct
16 Correct 133 ms 12564 KB Output is correct
17 Correct 130 ms 12532 KB Output is correct
18 Correct 117 ms 12216 KB Output is correct
19 Correct 121 ms 12212 KB Output is correct
20 Correct 137 ms 12348 KB Output is correct
21 Correct 124 ms 12324 KB Output is correct
22 Correct 126 ms 12356 KB Output is correct
23 Correct 117 ms 12268 KB Output is correct
24 Correct 117 ms 12152 KB Output is correct