Submission #1039917

#TimeUsernameProblemLanguageResultExecution timeMemory
1039917ZicrusHorses (IOI15_horses)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "horses.h" using namespace std; typedef long long ll; namespace Sol2 { ll n, pow2; vector<ll> segMul, segMax; vector<bool> segOF; vector<ll> x, y; vector<ll> lnk; vector<ll> effY; #define MOD (1000000007) int getPrev2Id(int i) { // TODO (inc) // If no 2, return id 0 // i can be negative!!! if (i < 0) return 0; i += pow2; while (segMul[i] == 1 && !segOF[i]) { if (!(i & 1)) { if ((i & (i-1)) == 0) return 0; i--; } i /= 2; } // now search down while (i < pow2) { if (segMul[2*i+1] == 1 && !segOF[2*i+1]) i = 2*i; else i = 2*i+1; } return i-pow2; } int getMax(ll low, ll high) { low += pow2; high += pow2; ll res = 0; while (low <= high) { if (low & 1) res = max(res, segMax[low++]); if (!(high & 1)) res = max(res, segMax[high--]); low /= 2; high /= 2; } return res; } void setX(int pos, int val) { if (val == x[pos]) return; int savedPos = pos; int old = x[pos]; x[pos] = val; pos += pow2; segMul[pos] = val; pos /= 2; while (pos) { segMul[pos] = segMul[2*pos] * segMul[2*pos+1]; if (segOF[2*pos] || segOF[2*pos+1] || segMul[pos] > MOD) { segMul[pos] %= MOD; segOF[pos] = true; } else { segOF[pos] = false; } pos /= 2; } pos = savedPos; if (val == 1) { ll prev2 = getPrev2Id(pos-1); lnk[prev2] = lnk[pos]; effY[prev2] = getMax(prev2, lnk[prev2]-1); return; } if (old > 1) { effY[pos] = getMax(pos, lnk[pos]-1); return; } if (pos == 0) { effY[pos] = getMax(pos, lnk[pos]-1); return; } ll prev2 = getPrev2Id(pos-1); lnk[pos] = lnk[prev2]; effY[pos] = getMax(pos, lnk[pos]-1); lnk[prev2] = pos; effY[prev2] = getMax(prev2, lnk[prev2]-1); return; } void setY(int pos, int val) { ll i = pos; y[i] = val; i += pow2; segMax[i] = val; i /= 2; while (i) { segMax[i] = max(segMax[2*i], segMax[2*i+1]); i /= 2; } ll prev2 = getPrev2Id(pos-1); effY[prev2] = getMax(prev2, lnk[prev2]-1); effY[pos] = getMax(pos, lnk[pos]-1); return; } int getOFId(int i = 1, ll prod = 1) { if (i >= pow2) return i-pow2; if (segOF[2*i+1] || segMul[2*i+1] * prod >= MOD) return getOFId(2*i+1, prod); return getOFId(2*i, prod * segMul[2*i+1]); } int getMulMod(int i) { int low = pow2, high = pow2+i; ll res = 1; while (low <= high) { if (low & 1) res = (res * segMul[low++]) % MOD; if (!(high & 1)) res = (res * segMul[high--]) % MOD; low /= 2; high /= 2; } return res % MOD; } int calc() { ll ofId = getOFId(); ll mx = effY[ofId]; ll offCnt = getMulMod(ofId); ll tCnt = 1; ll mxRes = (effY[ofId] * offCnt) % MOD; ofId = lnk[ofId]; if (!segOF[1]) { offCnt = 1; ofId = 0; mx = 0; } for (int i = ofId; i < n; i = lnk[i]) { offCnt *= x[i]; offCnt %= MOD; tCnt *= x[i]; ll val = tCnt * effY[i]; if (val > mx) { mx = val; mxRes = (offCnt * effY[i]) % MOD; } } return mxRes; } int init(int N, int X[], int Y[]) { n = N; pow2 = 1ll << (ll)ceil(log2(n)); x = vector<ll>(n); y = vector<ll>(n); lnk = vector<ll>(n); effY = vector<ll>(n); ll lastNon1 = n; for (int i = n-1; i >= 0; i--) { x[i] = X[i]; y[i] = Y[i]; lnk[i] = lastNon1; if (x[i] > 1) lastNon1 = i; } segMul = vector<ll>(2*pow2, 1); segMax = vector<ll>(2*pow2, 1); segOF = vector<bool>(2*pow2); for (int i = 0; i < n; i++) { segMul[pow2+i] = x[i]; segMax[pow2+i] = y[i]; } for (int i = pow2-1; i > 0; i--) { segMul[i] = segMul[2*i] * segMul[2*i+1]; if (segOF[2*i] || segOF[2*i+1] || segMul[i] >= MOD) { segMul[i] %= MOD; segOF[i] = true; } segMax[i] = max(segMax[2*i], segMax[2*i+1]); } for (int i = 0; i < n; i = lnk[i]) { if (lnk[i] == i+1) effY[i] = y[i]; else effY[i] = getMax(i, lnk[i]-1); } return calc(); } int updateX(int pos, int val) { setX(pos, val); ll val111 = effY[3493]; ll id = find(y.begin(), y.end(), 999825195) - y.begin(); ll v = calc(); return v; } int updateY(int pos, int val) { bool hi = true; setY(pos, val); ll v = calc(); return v; }

Compilation message (stderr)

horses.cpp: In function 'int Sol2::getPrev2Id(int)':
horses.cpp:23:7: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   23 |     i += pow2;
      |     ~~^~~~~~~
horses.cpp:36:13: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   36 |     return i-pow2;
      |            ~^~~~~
horses.cpp: In function 'int Sol2::getMax(ll, ll)':
horses.cpp:47:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   47 |     return res;
      |            ^~~
horses.cpp: In function 'void Sol2::setX(int, int)':
horses.cpp:53:20: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
   53 |     int old = x[pos];
      |                    ^
horses.cpp:55:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   55 |     pos += pow2;
      |     ~~~~^~~~~~~
horses.cpp: In function 'int Sol2::getOFId(int, ll)':
horses.cpp:111:28: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  111 |     if (i >= pow2) return i-pow2;
      |                           ~^~~~~
horses.cpp: In function 'int Sol2::getMulMod(int)':
horses.cpp:117:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  117 |     int low = pow2, high = pow2+i;
      |               ^~~~
horses.cpp:117:32: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  117 |     int low = pow2, high = pow2+i;
      |                            ~~~~^~
horses.cpp:124:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  124 |     return res % MOD;
      |                ^
horses.cpp: In function 'int Sol2::calc()':
horses.cpp:130:27: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  130 |     ll offCnt = getMulMod(ofId);
      |                           ^~~~
horses.cpp:139:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  139 |     for (int i = ofId; i < n; i = lnk[i]) {
      |                  ^~~~
horses.cpp:139:40: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
  139 |     for (int i = ofId; i < n; i = lnk[i]) {
      |                                        ^
horses.cpp:149:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  149 |     return mxRes;
      |            ^~~~~
horses.cpp: In function 'int Sol2::init(int, int*, int*)':
horses.cpp:159:19: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  159 |     for (int i = n-1; i >= 0; i--) {
      |                  ~^~
horses.cpp:172:22: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  172 |     for (int i = pow2-1; i > 0; i--) {
      |                  ~~~~^~
horses.cpp:180:37: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
  180 |     for (int i = 0; i < n; i = lnk[i]) {
      |                                     ^
horses.cpp: In function 'int Sol2::updateX(int, int)':
horses.cpp:193:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  193 |  return v;
      |         ^
horses.cpp:190:8: warning: unused variable 'val111' [-Wunused-variable]
  190 |     ll val111 = effY[3493];
      |        ^~~~~~
horses.cpp:191:8: warning: unused variable 'id' [-Wunused-variable]
  191 |     ll id = find(y.begin(), y.end(), 999825195) - y.begin();
      |        ^~
horses.cpp: In function 'int Sol2::updateY(int, int)':
horses.cpp:200:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  200 |  return v;
      |         ^
horses.cpp:197:10: warning: unused variable 'hi' [-Wunused-variable]
  197 |     bool hi = true;
      |          ^~
horses.cpp: At global scope:
horses.cpp:201:1: error: expected '}' at end of input
  201 | }
      | ^
horses.cpp:7:16: note: to match this '{'
    7 | namespace Sol2 {
      |                ^