Submission #1241918

#TimeUsernameProblemLanguageResultExecution timeMemory
1241918shiori_chan즐거운 사진 수집 (JOI13_collecting)C++17
0 / 100
930 ms98888 KiB
#include <iostream> #include <vector> #include <random> #include <algorithm> #include <chrono> #define all(x) x.begin(), x.end() #define vi vector <int> using namespace std; typedef long long ll; #define int long long const int nd = 1048576 + 1; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int> dist(1 , (int)2e9); vector <vi> segtree(2 , vi(4 * nd)) , count_node(2 , vi(22 , 0)); int timer = 1; int base = 0; bool ar = 0; void build(int id , int l , int r , int layer , vi &cnt , vi &st){ if(l == r){ st[id] = 0; return; } int mid = (r + l) / 2; build(id * 2 , l , mid , layer + 1 , cnt , st); build(id * 2 + 1 , mid + 1 , r , layer + 1 , cnt , st); st[id] = ++ timer * (st[id * 2] != st[id * 2 + 1]); ++ cnt[layer]; } void up(int id , int l , int r , int x , int layer , vi &cnt, vi &st){ if(l > x || r < x) return; if(l == r){ st[id] ^= 1; return; } int mid = (r + l) / 2; up(id * 2 , l , mid , x , layer + 1 , cnt , st); up(id * 2 + 1 , mid + 1 , r , x , layer + 1 , cnt , st); int pre = st[id]; st[id] = ++ timer * (st[id * 2] != st[id * 2 + 1]); if(!pre && st[id]) -- cnt[layer] , base -= count_node[ar][layer]; else if(pre && !st[id]) ++ cnt[layer] , base += count_node[ar][layer]; } void solve(){ int n , q; cin >> n >> q; int num_layer = n; n = (1 << n); int all = 0; for(int i = 0;i < num_layer; ++ i) all += (1 << i) * (1 << i); base = all; build(1 , 1 , n , 0 , count_node[0] , segtree[0]); build(1 , 1 , n , 0 , count_node[1] ,segtree[1]); while(q --){ int t , x; cin >> t >> x; ar = t ^ 1; up(1 , 1 , n , x , 0 , count_node[t] , segtree[t]); cout << (all - base) * 4 + 1 << '\n'; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); #define task "task" if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } solve(); return 0; }

Compilation message (stderr)

collecting.cpp: In function 'int main()':
collecting.cpp:78:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |                 freopen(task".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
collecting.cpp:79:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |                 freopen(task".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...