Submission #251138

#TimeUsernameProblemLanguageResultExecution timeMemory
251138anakib1Horses (IOI15_horses)C++17
0 / 100
40 ms32760 KiB
#include <iostream> #include <cmath> #include <algorithm> #include <stdio.h> #include <cstring> #include <string> #include <cstdlib> #include <vector> #include <bitset> #include <map> #include <chrono> #include <functional> #include <unordered_set> #include <unordered_map> #include <numeric> #include <queue> #include <ctime> #include <stack> #include <set> #include <list> #include <deque> #include <iomanip> #include <sstream> #include <fstream> #include <stdarg.h> #include <utility> using namespace std; #define pb push_back #define mp make_pair #define ll long long #define ull unisgned long long #define ld long double #define all(a) a.begin(), a.end() #define SORT(a) sort(all(a)) #define pii pair<int, int> #define tii triple<int, int, int> #define e 1e-7 #define PI acos(-1) #define sz(a) (int)(a.size()) #define inf 1e17 #define vi vector<int> #define F first #define S second #define rng(x) for(int _ = 0; _ < (x); _++) #define rngi(i, x) for(int i = 0; i < (x); i++) #define rngsi(s, i, x) for(int i = (s); i <(x); i++) #define problem "" template<typename A, typename B, typename C> struct triple{ A X; B Y; C Z; triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {} }; template<typename A, typename B, typename C> triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0){ return triple<A, B, C>(a, b, c); } template<typename A, typename B, typename C> bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b){ if (a.X != b.X) return a.X < b.X; if (a.Y != b.Y) return a.Y < b.Y; return a.Z < b.Z; } template<typename T, typename SS> ostream& operator<<(ostream& ofs, const pair<T, SS>& p){ ofs << "( " << p.F << " , " << p.S << " )"; return ofs; } template<typename T> void print(T a){ for (auto i : a) cout << i << ' '; cout << '\n'; } template<typename T> T max(T a, T b, T c){ return max(a, max(b, c)); } template<typename T> T min(T a, T b, T c){ return min(a, min(b, c)); } template<typename T, typename D> D min(T a){ return *min_element(all(a)); } template<typename T, typename D> D max(T a){ return *max_element(all(a)); } struct custom_hash{ static uint64_t splitmix64(uint64_t x){ x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const{ static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; #define int long long int n; vi c, p; #define mxn 50001 const int mod = 1e9 + 7; int tree[4 * mxn]; int prod[4 * mxn]; int gtm(int v, int l, int r, int _l, int _r){ if(r <_l || _r < l ) return 0; if(_l <= l && r <= _r) return tree[v]; int m = l + r >> 1; return max(gtm(v << 1, l, m, _l, _r), gtm(v << 1 | 1, m + 1, r, _l, _r)); } int gtp(int v, int l, int r, int _l, int _r){ if(r <_l || _r < l ) return 1; if(_l <= l && r <= _r) return tree[v]; int m = l + r >> 1; return (gtm(v << 1, l, m, _l, _r) * gtm(v << 1 | 1, m + 1, r, _l, _r)) % mod; } void chm(int v, int l, int r, int p, int k){ if(l == r) return void(tree[v] = k); int m = l + r >> 1; if(p <= m) chm(v << 1, l, m, p, k); else chm(v << 1 | 1, m + 1, r, p, k); tree[v] = max(tree[v << 1], tree[v << 1 | 1]); } void chp(int v, int l, int r, int p, int k){ if(l == r) return void(prod[v] = k); int m = l + r >> 1; if(p <= m) chp(v << 1, l, m, p, k); else chp(v << 1 | 1, m + 1, r, p, k); prod[v] = (prod[v << 1] * prod[v << 1 | 1]) % mod; } int getm(int l, int r){ return gtm(1, 0, n - 1, l, r); } int getp(int l, int r){return gtp(1,0,n-1,l,r);} set<int> id; int solve(){ int prod = 1; int best = n - 1; int pbest = 1; int en = n; for(auto it = id.rbegin(); it!=id.rend(); it++){ int i = *it; int p = getm(i, en - 1); if(prod <= p){ best = i; prod = p; pbest = p; } prod *= c[i]; if(prod > 1e9) break; en = i; } prod = getp(0, best); prod *= pbest; prod %= mod; return prod; }; #undef int int init(int N, int X[], int Y[]){ #define int long long n = N; c = p = vi(n); rngi(i, n) c[i]=X[i], p[i] = Y[i]; memset(tree, 0, sizeof(tree)); memset(prod, 1, sizeof(prod)); rngi(i, n) chm(1, 0, n - 1, i, c[i]); rngi(i, n) chp(1, 0, n - 1, i, p[i]); rngi(i, n) if(!i || p[i] > 1) id.insert(i); return solve(); #undef int } int updateX(int pos, int val) { chp(1, 0, n-1, pos, val); if(id.find(pos) != id.end()) id.erase(pos); if(!pos || val > 1) id.insert(pos); c[pos] = val; return solve(); } int updateY(int pos, int val) { chm(1, 0, n-1, pos, val); p[pos] = val; return solve(); }/* signed main() { if(0){ freopen(problem".in", "r", stdin); freopen(problem".out", "w", stdout); } srand(time(NULL)); cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int t = 1; //cin >> t; rng(t) solve(); } */

Compilation message (stderr)

horses.cpp: In function 'long long int gtm(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:128:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int m = l + r >> 1;
             ~~^~~
horses.cpp: In function 'long long int gtp(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:134:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int m = l + r >> 1;
             ~~^~~
horses.cpp: In function 'void chm(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:137:43: warning: declaration of 'p' shadows a global declaration [-Wshadow]
 void chm(int v, int l, int r, int p, int k){
                                           ^
horses.cpp:114:7: note: shadowed declaration is here
 vi c, p;
       ^
horses.cpp:139:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int m = l + r >> 1;
             ~~^~~
horses.cpp: In function 'void chp(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:144:43: warning: declaration of 'p' shadows a global declaration [-Wshadow]
 void chp(int v, int l, int r, int p, int k){
                                           ^
horses.cpp:114:7: note: shadowed declaration is here
 vi c, p;
       ^
horses.cpp:146:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int m = l + r >> 1;
             ~~^~~
horses.cpp: In function 'long long int solve()':
horses.cpp:158:9: warning: declaration of 'prod' shadows a global declaration [-Wshadow]
     int prod = 1;
         ^~~~
horses.cpp:121:5: note: shadowed declaration is here
 int prod[4 * mxn];
     ^~~~
horses.cpp:164:13: warning: declaration of 'p' shadows a global declaration [-Wshadow]
         int p = getm(i, en - 1);
             ^
horses.cpp:114:7: note: shadowed declaration is here
 vi c, p;
       ^
horses.cpp:169:19: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
         if(prod > 1e9) break;
                   ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:189:17: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return solve();
            ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:197:17: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return solve();
            ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:203:17: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return solve();
            ~~~~~^~
#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...