제출 #603819

#제출 시각아이디문제언어결과실행 시간메모리
603819nekiHorses (IOI15_horses)C++14
17 / 100
254 ms111564 KiB
#include <bits/stdc++.h> #define ll long long #define vc vector using namespace std; const ll mn=500100, mod=1000000007; ll x[mn], y[mn], n; ll tpro[2 * mn]; ll tmax[2 * mn]; set<ll> act; ll my[mn]; void updpro(ll pos, ll val){ for (tpro[pos += mn]=val; pos > 1; pos >>= 1) tpro[pos>>1]=(tpro[pos] * tpro[pos^1])%mod; } void updmax(ll pos, ll val){ for (tmax[pos += mn]=val; pos > 1; pos >>= 1) tmax[pos>>1]=max(tmax[pos], tmax[pos^1]); } ll getpro(ll l, ll r){ ll ret=1; for(l+=mn, r+=mn;l<r;l>>=1, r>>=1){ //assert(l>=0 and r>=0); if(l&1) ret*=tpro[l++]; if(r&1) ret*=tpro[--r]; ret%=mod; assert(ret>=0); } return ret; } ll getmax(ll l, ll r){ ll ret=0; for(l+=mn, r+=mn;l<r;l>>=1, r>>=1){ if(l&1) ret=max(ret, tmax[l++]); if(r&1) ret=max(ret, tmax[--r]); } return ret; } void getmy(ll pos){ ll l=pos, r; auto pr=act.upper_bound(pos); if(pr==act.end()) r=n; else r=(*pr); //cout << l <<" " << r << " " << getmax(l, r)<<endl; my[pos]=getmax(l, r); } ll getyear(ll pos){ //cout << pos << " " << getpro(0, pos+1) <<" " << y[pos]<< endl; //assert(act.count(pos)); ll ret=getpro(0, pos+1) * my[pos]; //assert(0<=getpro(0, pos+1)); //assert(0<=my[pos]); ret%=mod; return ret; } ll getans(){ vc<ll> preglej; auto poi = act.end(); for(ll i=0;i<min((ll)100, (ll)act.size());++i){ --poi; preglej.push_back(*poi); } reverse(preglej.begin(), preglej.end()); ll best=0, cur=1; for(ll i=1;i<preglej.size();++i){ cur*=x[preglej[i]]; if(my[preglej[best]]<cur or my[preglej[best]]<cur * my[preglej[i]]) best=i, cur=1; } //assert(0<=preglej[best] and preglej[best]<n); ll ret=getyear(preglej[best]); //assert(0<=ret and ret<mod); return ret; } int updateX(int pos, int val){ if(x[pos]>1 or pos==0) act.erase(pos); x[pos]=val;updpro(pos, val); if(x[pos]>1 or pos==0) act.insert(pos); auto zau = act.upper_bound(pos); --zau; getmy(*zau); if(zau!=act.begin()){--zau; getmy(*zau);} return getans(); } int updateY(int pos, int val){ y[pos]=val;updmax(pos, val); auto poi=act.upper_bound(pos);--poi; getmy(*poi); return getans(); } int init(int N, int X[], int Y[]){ n=N;for(ll i=0;i<n;++i) x[i]=X[i], y[i]=Y[i]; for(ll i=0;i<n;++i) updpro(i, X[i]), updmax(i, Y[i]); for(ll i=0;i<n;++i) if(x[i]>1 or i==0) act.insert(i); for(ll i=0;i<n;++i) if(x[i]>1 or i==0) getmy(i); return getans(); }

컴파일 시 표준 에러 (stderr) 메시지

horses.cpp: In function 'long long int getans()':
horses.cpp:74:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     for(ll i=1;i<preglej.size();++i){
      |                ~^~~~~~~~~~~~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:94:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   94 |     return getans();
      |            ~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:101:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  101 |     return getans();
      |            ~~~~~~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:109:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  109 |     return getans();
      |            ~~~~~~^~
#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...