Submission #332007

#TimeUsernameProblemLanguageResultExecution timeMemory
332007hackxsarasGame (IOI13_game)C++14
37 / 100
13090 ms13944 KiB
#include <bits/stdc++.h> #include <chrono> #include <game.h> using namespace std; using namespace std::chrono; // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") // #pragma optimization_level 3 // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define pb push_back #define galen_colin {ios_base::sync_with_stdio(false);} #define orz {cin.tie(NULL); cout.tie(NULL);} #define fix(prec) {cout << setprecision(prec) << fixed;} #define mp make_pair #define f first #define s second #define all(v) v.begin(), v.end() typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v); template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; } template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << ""; for(int i = 0; i < v.size(); i++) {if (i) cout << " "; cout << v[i];} return cout << "\n"; } template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) { cin >> p.first; return cin >> p.second; } template<typename A> istream& operator>>(istream& cin, vector<A> &v) { for(auto &x:v)cin>>x; return cin; } ll min(ll a, int b){return min(a, (ll) b);} ll min(int a, ll b){return min(b, (ll) a);} ll max(ll a, int b){return max(a, (ll) b);} ll max(int a, ll b){return max(b, (ll) a);} void usaco(string filename) { // #pragma message("be careful, freopen may be wrong") freopen((filename + ".in").c_str(), "r", stdin); freopen((filename + ".out").c_str(), "w", stdout); } const ld pi = 3.14159265358979323846; const ll mod = 1000000007; // const ll mod = 998244353; // ll mod; const ll INF = 1e9+7; ll n, m, k, q, l, r, x, y, z; map<pair<pair<int,int>, pair<int,int>>, ll> segtree; ll __gcd(ll &p, ll& q, ll& r, ll &s){ //cout<<p<<" "<<q<<" "<<r<<" "<<s<<" = "<<__gcd(p, __gcd(q, __gcd(r, s)))<<"\n"; return __gcd(p, __gcd(q, __gcd(r, s))) ; } void init(int r, int c){ n = r, m = c; } ll update(int sx, int sy, int ex, int ey, int& a, int& b, ll& k){ if(sx > ex || sy > ey) return 0; if(a > ex || a < sx || b > ey || b < sy){ auto it = segtree.find({{sx, sy}, {ex, ey}}); if(it != segtree.end()) return (*it).s; return 0; } if(sx == ex && sy == ey){ return segtree[{{sx,sy}, {ex, ey}}] = k; } int mx = (sx + ex)/2, my = (sy + ey)/2; ll p = update(sx,sy,mx,my,a,b,k), q = update(sx,my+1,mx,ey,a,b,k), r = update(mx+1,sy,ex,my,a,b,k), s = update(mx+1,my+1,ex,ey,a,b,k); return segtree[{{sx, sy},{ex, ey}}] = __gcd(p,q,r,s); } void update(int a, int b, ll k){ update(0, 0, n-1, m-1, a, b, k); } ll calculate(int sx,int sy, int ex, int ey, int& rsx, int& rsy, int& rex, int& rey){ if(sx > ex || sy > ey) return 0; if(rsx > ex || rex < sx || rsy > ey || rey < sy) return 0; if(sx >= rsx && sy >= rsy && ex<=rex && ey<=rey){ auto it = segtree.find({{sx, sy}, {ex, ey}}); if(it != segtree.end()) return (*it).s; return 0; } int mx = (sx + ex)/2, my = (sy + ey)/2; ll p = calculate(sx,sy,mx,my,rsx, rsy, rex, rey), q = calculate(sx,my+1,mx,ey,rsx, rsy, rex, rey), r = calculate(mx+1,sy,ex,my,rsx, rsy, rex, rey), s = calculate(mx+1,my+1,ex,ey,rsx, rsy, rex, rey); return __gcd(p,q,r,s); } /* 20 6 15 0 14 0 0 0 1 2 = 14 0 0 0 1 = 6 0 2 0 2 = 15 1 0 1 1 = 14 1 2 1 2 = 0 */ ll calculate(int sx, int sy, int ex, int ey){ return calculate(0, 0, n-1, m-1, sx, sy, ex, ey); } // void showall(){ // // for(int i=0;i<n;i++){ // // for(int j=0;j<m;j++){ // // cout<<segtree[{{i,j},{i,j}}]<<" "; // // } // // cout<<"\n"; // // } // } // int main() { // init(2,3); // update(0,0,20); showall(); // update(0,2,15); showall(); // update(1,1,12); showall(); // cout<<calculate(0,0,0,2)<<"\n"; // cout<<calculate(0,0,1,1)<<"\n"; // update(0,1,6); showall(); // update(1,1,14); showall(); // cout<<calculate(0,0,0,2)<<"\n"; // cout<<calculate(0,0,1,1)<<"\n"; // }

Compilation message (stderr)

game.cpp: In function 'void usaco(std::string)':
game.cpp:56:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   56 |     freopen((filename + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:57:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   57 |     freopen((filename + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...