제출 #1125967

#제출 시각아이디문제언어결과실행 시간메모리
1125967underwaterkillerwhale즐거운 사진 수집 (JOI13_collecting)C++20
100 / 100
1288 ms60020 KiB
//#include"holiday.h" #include <bits/stdc++.h> #define ll long long #define rep(i,m,n) for(int i=(m); i<=(n); i++) #define REB(i,m,n) for(int i=(m); i>=(n); i--) #define pii pair<int,int> #define pll pair<ll,ll> #define MP make_pair #define fs first #define se second #define bit(msk, i) ((msk >> i) & 1) #define iter(id, v) for(auto id : v) #define pb push_back #define SZ(v) (ll)v.size() #define ALL(v) v.begin(),v.end() using namespace std; mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count()); ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); } const int N = 2e6 + 7; const int Mod = 1e9 + 7;///lon const int INF = 1e9 + 7; const ll BASE = 137; const int szBL = 450; int n, Q; pii qr[N]; int cnt[2][25][5];///0:row 1:collum struct Segment_Tree { int m; int st[N << 2]; void build (int id, int l, int r, int typ, int high) { if (l == r) { cnt[typ][high][0]++; return; } int mid = l + r >> 1; build (id << 1, l, mid, typ, high + 1); build (id << 1 | 1, mid + 1, r, typ, high + 1); cnt[typ][high][0]++; } void init (int n, int typ) { m = n; build(1, 1, n, typ, 1); } int mer (int lc, int rc) { if (lc == 2 || rc == 2 || lc != rc) return 2; else return lc; } void update (int id, int l, int r, int pos, int typ, int high) { if (l > pos || r < pos) return; if (l == r) { cnt[typ][high][st[id]]--; st[id] ^= 1; cnt[typ][high][st[id]]++; return; } int mid = l + r >> 1; update (id << 1, l, mid, pos, typ, high + 1); update (id << 1 | 1, mid + 1, r, pos, typ, high + 1); cnt[typ][high][st[id]]--; st[id] = mer(st[id << 1], st[id << 1 | 1]); cnt[typ][high][st[id]]++; // cout << typ <<" "<<st[id] <<" dasdsad\n"; } void update (int pos, int typ) { update (1, 1, m, pos, typ, 1); } }ST[2]; void solution() { cin >> n >> Q; rep (i, 0, 1) ST[i].init(1 << n, i); rep (q, 1, Q) { cin >> qr[q].fs >> qr[q].se; if (qr[q].fs == 0) ST[0].update(qr[q].se, 0); else ST[1].update(qr[q].se, 1); ll res = 0; REB (i, n + 1, 1) { // rep (typ, 0, 1) { // rep (k, 0, 2) cout <<i<<","<<typ<<","<<k<<": "<<cnt[typ][i][k] <<"\n"; // } // cout<<"\n"; // cout<<"\n"; res += 1LL * cnt[0][i][2] * (cnt[1][i][1] + cnt[1][i][2] + cnt[1][i][0]); res += 1LL * (cnt[0][i][1] + cnt[0][i][0]) * cnt[1][i][2]; if (i <= n) res -= 4LL * (cnt[0][i][1] + cnt[0][i][0]) * (cnt[1][i][0] + cnt[1][i][1]); res += 1LL * (cnt[0][i][0] + cnt[0][i][1]) * (cnt[1][i][0] + cnt[1][i][1]); } cout <<res <<"\n"; } } #define file(name) freopen(name".inp","r",stdin); \ freopen(name".out","w",stdout); int main () { // file("c"); ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0); int num_Test = 1; // cin >> num_Test; while (num_Test--) solution(); } /* no bug challenge +33 2 1 0 1 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...