제출 #731072

#제출 시각아이디문제언어결과실행 시간메모리
731072Mher777XORanges (eJOI19_xoranges)C++17
100 / 100
138 ms14492 KiB
//////////////////////////////// Mher777 /* -------------------- Includes -------------------- */ #include <iostream> #include <iomanip> #include <array> #include <string> #include <algorithm> #include <cmath> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <vector> #include <stack> #include <queue> #include <deque> #include <bitset> #include <list> #include <iterator> #include <numeric> #include <complex> #include <utility> #include <random> #include <fstream> using namespace std; /* -------------------- Typedefs -------------------- */ typedef int itn; typedef long long ll; typedef unsigned long long ull; typedef float fl; typedef double db; typedef long double ld; /* -------------------- Usings -------------------- */ using vi = vector<int>; using vll = vector<ll>; using mii = map<int, int>; using mll = map<ll, ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; /* -------------------- Defines -------------------- */ #define ff first #define ss second #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define mpr make_pair #define yes cout<<"YES\n" #define no cout<<"NO\n" #define all(x) (x).begin(), (x).end() /* -------------------- Constants -------------------- */ const int MAX = int(1e9 + 5); const ll MAXL = ll(1e18 + 5); const ll MOD = ll(1e9 + 7); const ll MOD2 = ll(998244353); /* -------------------- Functions -------------------- */ void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); return; } void precision(int x) { cout.setf(ios::fixed | ios::showpoint); cout.precision(x); return; } ll gcd(ll a, ll b) { while (b) { a %= b; swap(a, b); } return a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll range_sum(ll a, ll b) { ll dif = a - 1, cnt = b - a + 1; ll ans = ((b - a + 1) * (b - a + 2)) / 2; ans += ((b - a + 1) * dif); return ans; } string to2(ll a) { string s = ""; for (ll i = a; i > 0; ) { ll k = i % 2; i /= 2; char c = k + 48; s += c; } if (a == 0) { s = "0"; } reverse(all(s)); return s; } bool isPrime(ll a) { if (a == 1) { return false; } for (ll i = 2; i * i <= a; i++) { if (a % i == 0) { return false; } } return true; } int dig_sum(ll a) { int sum = 0; while (a) { sum += int(a % 10); a /= 10; } return sum; } ll binpow(ll a, int b) { ll ans = 1; while (b) { if ((b & 1) == 1) { ans *= a; } b >>= 1; a *= a; } return ans; } ll binpow_by_mod(ll a, ll b, ll mod) { ll ans = 1; while (b) { if ((b & 1) == 1) { ans *= a; ans %= mod; } b >>= 1; a *= a; a %= mod; } return ans; } ll factorial(int a) { ll ans = 1; for (int i = 2; i <= a; i++) { ans *= ll(i); } return ans; } ll factorial_by_mod(int a, ll mod) { ll ans = 1; for (int i = 2; i <= a; i++) { ans *= ll(i); ans %= mod; } return ans; } /* -------------------- Solution -------------------- */ const int N = 200005; ll a[N], a1[N], a2[N], t1[N * 4], t2[N * 4]; int par1[N], par2[N]; void bld(int l, int r, int pos, int type) { int mid = (l + r) / 2; if (l == r) { if (type == 1) { t1[pos] = a1[l]; par1[l] = pos; } else { t2[pos] = a2[l]; par2[l] = pos; } } else { bld(l, mid, 2 * pos, type); bld(mid + 1, r, 2 * pos + 1, type); if (type == 1) { t1[pos] = t1[2 * pos] ^ t1[2 * pos + 1]; } else { t2[pos] = t2[2 * pos] ^ t2[2 * pos + 1]; } } } ll qry(int l, int r, int tl, int tr, int pos, int type) { int mid = (tl + tr) / 2; if (l == tl && r == tr) { return (type == 1 ? t1[pos] : t2[pos]); } if (r <= mid) { return qry(l, r, tl, mid, 2 * pos, type); } if (l > mid) { return qry(l, r, mid + 1, tr, 2 * pos + 1, type); } return qry(l, mid, tl, mid, 2 * pos, type) ^ qry(mid + 1, r, mid + 1, tr, 2 * pos + 1, type); } void upd(int ind, ll val, int type) { int p; if (type == 1) { p = par1[ind]; t1[p] = val; a1[ind] = val; } else { p = par2[ind]; t2[p] = val; a2[ind] = val; } p /= 2; while (p) { if (type == 1) { t1[p] = t1[2 * p] ^ t1[2 * p + 1]; } else { t2[p] = t2[2 * p] ^ t2[2 * p + 1]; } p /= 2; } } void slv() { int n, q, n1, n2; cin >> n >> q; // 1 -> kent // 2 -> zuyg for (int i = 1; i <= n; i++) { cin >> a[i]; if (i % 2 == 1) { a1[(i + 1) / 2] = a[i]; } else { a2[i / 2] = a[i]; } } if (n % 2 == 0) { n1 = n / 2, n2 = n / 2; bld(1, n / 2, 1, 1); bld(1, n / 2, 1, 2); } else { n1 = (n + 1) / 2, n2 = n / 2; bld(1, (n + 1) / 2, 1, 1); if (n != 1) { bld(1, n / 2, 1, 2); } } while (q--) { int type; cin >> type; if (type == 1) { int ind; ll val; cin >> ind >> val; int tp = (ind % 2 == 1 ? 1 : 2); if (ind % 2 == 1) { ind = ind / 2 + 1; } else { ind /= 2; } upd(ind, val, tp); } else { int l, r; cin >> l >> r; if ((r - l + 1) % 2 == 0) { cout << 0 << '\n'; } else { if (l % 2 == 0) { cout << qry(l / 2, r / 2, 1, n2, 1, 2) << '\n'; } else { if (r % 2 == 1) { r /= 2; r++; } else { r /= 2; } cout << qry(l / 2 + 1, r, 1, n1, 1, 1) << '\n'; } } } } } void cs() { int tstc = 1; //cin >> tstc; while (tstc--) { slv(); } } void precalc() { return; } int main() { fastio(); //precalc(); //precision(1); cs(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

xoranges.cpp: In function 'll range_sum(ll, ll)':
xoranges.cpp:93:18: warning: unused variable 'cnt' [-Wunused-variable]
   93 |  ll dif = a - 1, cnt = b - a + 1;
      |                  ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...