Submission #984230

#TimeUsernameProblemLanguageResultExecution timeMemory
984230SmuggingSpunHorses (IOI15_horses)C++14
77 / 100
1558 ms44352 KiB
#include "horses.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; const int mod = 1e9 + 7; const int lim = 5e5 + 5; int power(int a, int b){ int ans = 1; for(; b > 0; b >>= 1, a = 1LL * a * a % mod){ if(b & 1){ ans = 1LL * ans * a % mod; } } return ans; } int n, pl[lim << 2], pr[lim << 2], temp[lim << 2], st[lim << 2], x[lim], x_st[lim << 2], y[lim], bit[lim]; int get_bit(int p){ int ans = 1; for(; p > 0; p -= p & -p){ ans = 1LL * ans * bit[p] % mod; } return ans; } void update_bit(int p, int x){ for(; p <= n; p += p & -p){ bit[p] = 1LL * bit[p] * x % mod; } } int get_x_prod(int id, int l, int r, int u, int v){ if(l > v || r < u){ return 1; } if(u <= l && v >= r){ return x_st[id]; } int m = (l + r) >> 1, left = get_x_prod(id << 1, l, m, u, v); if(left == mod){ return mod; } return min(ll(mod), 1LL * left * get_x_prod(id << 1 | 1, m + 1, r, u, v)); } int merge(int id){ int l = st[id << 1], r = st[id << 1 | 1]; if(l == 0){ return r; } if(r == 0){ return l; } if(pl[id] != l || pr[id] != r){ temp[id] = get_x_prod(1, 1, n, l + 1, r); } return 1LL * temp[id] * y[r] < ll(y[l]) ? l : r; } void update_X(int id, int l, int r, int p, int X){ if(l == r){ update_bit(l, 1LL * power(x[l], mod - 2) * X % mod); x[st[id] = l] = X; x_st[id] = X; return; } int m = (l + r) >> 1; if(m < p){ update_X(id << 1 | 1, m + 1, r, p, X); } else{ update_X(id << 1, l, m, p, X); } st[id] = merge(id); x_st[id] = min(ll(mod), 1LL * x_st[id << 1] * x_st[id << 1 | 1]); } void update_Y(int p, int Y){ y[p] = Y; int id = 1, l = 1, r = n; while(l < r){ int m = (l + r) >> 1; id <<= 1; if(m < p){ l = m + 1; id |= 1; } else{ r = m; } } while((id >>= 1) > 0){ st[id] = merge(id); } } int init(int N, int X[], int Y[]){ n = N; fill(bit, bit + lim, 1); for(int i = 1; i <= n; i++){ y[i] = Y[i - 1]; update_bit(i, x[i] = X[i - 1]); } memset(pl, -1, sizeof(pl)); memset(pr, -1, sizeof(pr)); fill(x_st, x_st + (lim << 2), 1); for(int i = 1; i <= n; i++){ update_X(1, 1, n, i, X[i - 1]); } return 1LL * get_bit(st[1]) * y[st[1]] % mod; } int updateX(int pos, int val){ update_X(1, 1, n, pos + 1, val); return 1LL * get_bit(st[1]) * y[st[1]] % mod; } int updateY(int pos, int val){ update_Y(pos + 1, val); return 1LL * get_bit(st[1]) * y[st[1]] % mod; }

Compilation message (stderr)

horses.cpp: In function 'int power(int, int)':
horses.cpp:9:40: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
    9 |  for(; b > 0; b >>= 1, a = 1LL * a * a % mod){
      |                            ~~~~~~~~~~~~^~~~~
horses.cpp:11:24: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   11 |    ans = 1LL * ans * a % mod;
      |          ~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int get_bit(int)':
horses.cpp:20:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   20 |   ans = 1LL * ans * bit[p] % mod;
      |         ~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void update_bit(int, int)':
horses.cpp:24:28: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   24 | void update_bit(int p, int x){
      |                        ~~~~^
horses.cpp:16:66: note: shadowed declaration is here
   16 | int n, pl[lim << 2], pr[lim << 2], temp[lim << 2], st[lim << 2], x[lim], x_st[lim << 2], y[lim], bit[lim];
      |                                                                  ^
horses.cpp:26:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   26 |   bit[p] = 1LL * bit[p] * x % mod;
      |            ~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int get_x_prod(int, int, int, int, int)':
horses.cpp:40:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   40 |  return min(ll(mod), 1LL * left * get_x_prod(id << 1 | 1, m + 1, r, u, v));
      |         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'void update_X(int, int, int, int, int)':
horses.cpp:57:48: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   57 |   update_bit(l, 1LL * power(x[l], mod - 2) * X % mod);
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:70:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   70 |  x_st[id] = min(ll(mod), 1LL * x_st[id << 1] * x_st[id << 1 | 1]);
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:103:41: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  103 |  return 1LL * get_bit(st[1]) * y[st[1]] % mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:107:41: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  107 |  return 1LL * get_bit(st[1]) * y[st[1]] % mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:111:41: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  111 |  return 1LL * get_bit(st[1]) * y[st[1]] % mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
#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...