Submission #289714

#TimeUsernameProblemLanguageResultExecution timeMemory
289714b00n0rpHorses (IOI15_horses)C++17
100 / 100
585 ms49276 KiB
#include "horses.h" #include<bits/stdc++.h> using namespace std; #define ll long long #define int ll #define pb push_back #define INF 1000000000 #define MOD 1000000007 #define mp make_pair const double PI=3.141592653589793238462643383279502884197169399375105820974944; #define REP(i,n) for (int i = 0; i < n; i++) #define FOR(i,a,b) for (int i = a; i < b; i++) #define REPD(i,n) for (int i = n-1; i >= 0; i--) #define FORD(i,a,b) for (int i = a; i >= b; i--) #define remax(a,b) a = max(a,b) #define remin(a,b) a = min(a,b) #define all(v) v.begin(),v.end() #define pii pair<int,int> #define F first #define S second #define mii map<int,int> #define vi vector<int> #define vvi vector<vi> #define itr :: iterator it #define WL(t) while(t --) #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) ((a)*(b))/gcd((a),(b)) #define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl; #define debug(x) cout << x << endl; #define debug2(x,y) cout << x << " " << y << endl; #define debug3(x,y,z) cout << x << " " << y << " " << z << endl; int power(int a,int b,int m = MOD){ if(b == 0) return 1; if(b == 1) return a; int x = power(a,b/2,m)%m; x = (x*x)%m; if(b%2) return (x*a)%m; return x; } int n,x[500005],y[500005],q,seg[1000005],seg2[1000005]; int seg3[1000005]; int quer(int l,int r){ // cout << l << " " << r << " ----> "; l += n; r += n+1; int ans = 1; while(l < r){ if(l%2){ ans *= seg2[l++]; remin(ans,(ll)2e9); } if(r%2){ ans *= seg2[--r]; remin(ans,(ll)2e9); } l /= 2; r /= 2; } // cout << ans << endl; return ans; } int quer2(int pos){ int ans = y[pos]; int l = n,r = pos+n+1; while(l < r){ if(l%2) ans = (ans*seg3[l++])%MOD; if(r%2) ans = (ans*seg3[--r])%MOD; l /= 2; r /= 2; } return ans; } signed init(signed _n, signed _X[], signed _Y[]) { n = _n; REP(i,n) x[i] = _X[i],seg2[i+n] = x[i],seg3[i+n] = x[i]; REP(i,n) y[i] = _Y[i],seg[i+n] = i; for(int i = n-1; i > 0; i --){ seg2[i] = min((ll)2e9,seg2[i*2]*seg2[i*2+1]); seg3[i] = (seg3[i*2]*seg3[i*2+1])%MOD; } for(int i = n-1; i > 0; i --){ int left = seg[i*2],right = seg[i*2+1]; if(left > right) swap(left,right); if(quer(left+1,right)*y[right] > y[left]){ seg[i] = right; } else seg[i] = left; } return (signed)quer2(seg[1]); } signed updateX(signed pos, signed val) { x[pos] = val; seg2[pos+n] = val; seg3[pos+n] = val; pos += n; for(int i = pos/2; i > 0; i /= 2){ seg2[i] = min((ll)2e9,seg2[i*2]*seg2[i*2+1]); seg3[i] = (seg3[i*2]*seg3[i*2+1])%MOD; } if(n <= 1000 and q <= 1000){ for(int i = pos/2; i > 0; i --){ int left = seg[i*2],right = seg[i*2+1]; if(left > right) swap(left,right); if(quer(left+1,right)*y[right] > y[left]){ seg[i] = right; } else seg[i] = left; } } else{ for(int i = pos/2; i > 0; i /= 2){ //----------------------------------------- int j = i+1; int left = seg[j*2],right = seg[j*2+1]; if(left > right) swap(left,right); if(quer(left+1,right)*y[right] > y[left]){ seg[j] = right; } else seg[j] = left; //----------------------------------------- left = seg[i*2],right = seg[i*2+1]; if(left > right) swap(left,right); if(quer(left+1,right)*y[right] > y[left]){ seg[i] = right; } else seg[i] = left; //----------------------------------------- j = i-1; left = seg[j*2],right = seg[j*2+1]; if(left > right) swap(left,right); if(quer(left+1,right)*y[right] > y[left]){ seg[j] = right; } else seg[j] = left; //----------------------------------------- } } return (signed)quer2(seg[1]); } signed updateY(signed pos, signed val) { y[pos] = val; pos += n; for(int i = pos/2; i > 0; i /= 2){ seg2[i] = min((ll)2e9,seg2[i*2]*seg2[i*2+1]); seg3[i] = (seg3[i*2]*seg3[i*2+1])%MOD; } if(n <= 1000 and q <= 1000){ for(int i = pos/2; i > 0; i --){ int left = seg[i*2],right = seg[i*2+1]; if(left > right) swap(left,right); if(quer(left+1,right)*y[right] > y[left]){ seg[i] = right; } else seg[i] = left; } } else{ for(int i = pos/2; i > 0; i /= 2){ //----------------------------------------- int j = i+1; int left = seg[j*2],right = seg[j*2+1]; if(left > right) swap(left,right); if(quer(left+1,right)*y[right] > y[left]){ seg[j] = right; } else seg[j] = left; //----------------------------------------- left = seg[i*2],right = seg[i*2+1]; if(left > right) swap(left,right); if(quer(left+1,right)*y[right] > y[left]){ seg[i] = right; } else seg[i] = left; //----------------------------------------- j = i-1; left = seg[j*2],right = seg[j*2+1]; if(left > right) swap(left,right); if(quer(left+1,right)*y[right] > y[left]){ seg[j] = right; } else seg[j] = left; //----------------------------------------- } } return (signed)quer2(seg[1]); }

Compilation message (stderr)

horses.cpp: In function 'int updateX(int, int)':
horses.cpp:103:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  103 |     pos += n;
      |     ~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:152:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  152 |     pos += n;
      |     ~~~~^~~~
#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...