제출 #297700

#제출 시각아이디문제언어결과실행 시간메모리
297700cfalasHorses (IOI15_horses)C++14
57 / 100
1559 ms87076 KiB
#pragma GCC target("avx") #pragma GCC optimize("Ofast") #include<bits/stdc++.h> #include "horses.h" using namespace std; #define FORi(i,a,b) for(int i=a;i<b;i++) #define MOD 1000000007 #define FOR(i,n) FORi(i,0,n) #define ll long long #define MID ((l+r)/2) #define len(x) ((int)((x).size())) template<typename T> struct seg_tree{ struct node{ T val; T laz; int left=-1; int right=-1; node() {val=0, laz=0, left=-1, right=-1;} node(T v) {val=v, laz=0, right=-1, left=-1;} }; vector<node> seg; static inline int N; const int RAND_VALUE=1; seg_tree(int n){N=n, seg.assign(1, node());} seg_tree(){seg.assign(1, node());} inline node merge(node par, node a, node b){ node ret; ret.left = par.left, ret.right = par.right; ret.val = max(a.val , b.val); return ret; } inline void update_node(int ind, int val, int l, int r){ seg[ind].val = val; } inline void create_children(int ind){ node par = seg[ind]; if(par.left==-1){ //cout<<"left\n"; par.left=seg.size(), seg.push_back(node()); } if(par.right==-1) par.right=seg.size(), seg.push_back(node()); seg[ind] = par; } void build(vector<T>& arr, int l=0, int r=N-1, int ind=0){ if(l==r) seg[ind] = node(arr[l]); else{ create_children(ind); build(arr,l,MID,seg[ind].left); build(arr,MID+1,r,seg[ind].right); seg[ind] = merge(seg[ind], seg[seg[ind].left], seg[seg[ind].right]); } } void update(int rl, int rr, int val, int l=0, int r=N-1, int ind=0){ if(rl<=l && r<=rr) update_node(ind, val,l,r); else if(rr<l || r<rl) return; else{ create_children(ind); update(rl,rr,val,l,MID,seg[ind].left); update(rl,rr,val,MID+1,r,seg[ind].right); seg[ind] = merge(seg[ind], seg[seg[ind].left], seg[seg[ind].right]); } } node _query(int rl, int rr, int l=0, int r=N-1, int ind=0){ if(rl<=l && r<=rr) return seg[ind]; else if(rl>r || l>rr) return RAND_VALUE; else{ create_children(ind); return merge(seg[ind], _query(rl, rr, l, MID, seg[ind].left), _query(rl,rr,MID+1,r,seg[ind].right)); } } T query(int l, int r){ return _query(l,r).val; } }; template<typename T> struct mult_seg_tree{ struct node{ T val; T laz; int left=-1; int right=-1; node() {val=1, laz=0, left=-1, right=-1;} node(T v) {val=v, laz=0, right=-1, left=-1;} }; vector<node> seg; static inline int N; const int RAND_VALUE=1; mult_seg_tree(int n){N=n, seg.assign(1, node());} mult_seg_tree(){seg.assign(1, node());} inline node merge(node par, node a, node b){ node ret; ret.left = par.left, ret.right = par.right; ret.val = a.val * b.val; return ret; } inline void update_node(int ind, int val, int l, int r){ seg[ind].val = val; } inline void down(node &par, int l, int r){ /* seg[par.left].val += par.laz * (MID-l+1); seg[par.right].val += par.laz * (r-MID); seg[par.left].laz = par.laz; seg[par.right].laz = par.laz; par.laz = 0; */ } inline void create_children(int ind){ node par = seg[ind]; if(par.left==-1){ //cout<<"left\n"; par.left=seg.size(), seg.push_back(node()); } if(par.right==-1) par.right=seg.size(), seg.push_back(node()); seg[ind] = par; } void build(vector<int>& arr, int l=0, int r=N-1, int ind=0){ if(l==r) seg[ind] = node(arr[l]); else{ create_children(ind); build(arr,l,MID,seg[ind].left); build(arr,MID+1,r,seg[ind].right); seg[ind] = merge(seg[ind], seg[seg[ind].left], seg[seg[ind].right]); } } void update(int pos, int val, int l=0, int r=N-1, int ind=0){ if(l==r && r==pos) update_node(ind, val,l,r); else if(pos<l || pos>r || l==r) return; else{ create_children(ind); down(seg[ind],l,r); update(pos,val,l,MID,seg[ind].left); update(pos,val,MID+1,r,seg[ind].right); seg[ind] = merge(seg[ind], seg[seg[ind].left], seg[seg[ind].right]); } } node _query(int rl, int rr, int l=0, int r=N-1, int ind=0){ if(rl<=l && r<=rr) return seg[ind]; else if(rl>r || l>rr) return RAND_VALUE; else{ create_children(ind); down(seg[ind],l,r); return merge(seg[ind], _query(rl, rr, l, MID, seg[ind].left), _query(rl,rr,MID+1,r,seg[ind].right)); } } T query(int l, int r){ return _query(l,r).val; } }; template<typename T> struct mult_mod_seg_tree{ struct node{ T val; T laz; int left=-1; int right=-1; node() {val=0, laz=0, left=-1, right=-1;} node(T v) {val=v, laz=0, right=-1, left=-1;} }; vector<node> seg; static inline int N; const int RAND_VALUE=1; mult_mod_seg_tree(int n){N=n, seg.assign(1, node());} mult_mod_seg_tree(){seg.assign(1, node());} inline node merge(node par, node a, node b){ node ret; ret.left = par.left, ret.right = par.right; ret.val = (((ll)a.val * ((ll)b.val))) % MOD; return ret; } inline void update_node(int ind, int val, int l, int r){ seg[ind].val = val; } inline void down(node &par, int l, int r){ /* seg[par.left].val += par.laz * (MID-l+1); seg[par.right].val += par.laz * (r-MID); seg[par.left].laz = par.laz; seg[par.right].laz = par.laz; par.laz = 0; */ } inline void create_children(int ind){ node par = seg[ind]; if(par.left==-1){ //cout<<"left\n"; par.left=seg.size(), seg.push_back(node()); } if(par.right==-1) par.right=seg.size(), seg.push_back(node()); seg[ind] = par; } void build(vector<T>& arr, int l=0, int r=N-1, int ind=0){ if(l==r) seg[ind] = node(arr[l]); else{ create_children(ind); build(arr,l,MID,seg[ind].left); build(arr,MID+1,r,seg[ind].right); seg[ind] = merge(seg[ind], seg[seg[ind].left], seg[seg[ind].right]); } } void update(int pos, int val, int l=0, int r=N-1, int ind=0){ if(l==r && r==pos) update_node(ind, val,l,r); else if(pos<l || pos>r || l==r) return; else{ create_children(ind); down(seg[ind],l,r); update(pos,val,l,MID,seg[ind].left); update(pos,val,MID+1,r,seg[ind].right); seg[ind] = merge(seg[ind], seg[seg[ind].left], seg[seg[ind].right]); } } node _query(int rl, int rr, int l=0, int r=N-1, int ind=0){ if(rl<=l && r<=rr) return seg[ind]; else if(rl>r || l>rr) return RAND_VALUE; else{ create_children(ind); down(seg[ind],l,r); return merge(seg[ind], _query(rl, rr, l, MID, seg[ind].left), _query(rl,rr,MID+1,r,seg[ind].right)); } } T query(int l, int r){ return _query(l,r).val%MOD; } }; typedef vector<int> vi; vi x; vector<int> y; vector<double> a; set<int> xx; clock_t start_timer; void time_start(){ start_timer = clock(); } void time_end(){ auto endt = clock(); //cout<<(double)(endt-start_timer) / CLOCKS_PER_SEC<<endl; } seg_tree<int> yseg; mult_seg_tree<double> xsegd; mult_mod_seg_tree<int> xsegm; #define FOA(v,qq) for(auto v : qq) int get_ans(){ auto it = xx.end(); it--; it--; int cnt=0; double maxa=0; int maxapos=-1, next=-1; // O(30) auto itt = xx.end(); ll pp=1; auto st = it; auto vv = yseg.query(0,yseg.N-1); while(itt!=xx.begin() && pp<vv) itt--, pp*=x[*itt], st=itt; int f = *itt; // O(30logN) while(1){ auto it2 = it; it2++; // O(logN) double c = xsegd.query(f, *it); assert(c>0); // O(logN) c*=(double)yseg.query(*it, *it2-1); //cout<<c<<endl; if(c>maxa){ maxa = c; maxapos = *it; next = *it2; } cnt++; if(it==st) break; it--; } // O(logN) int c = xsegm.query(0, maxapos); c= ((ll) c * (ll) yseg.query(maxapos, next-1) ) %MOD; return c; } int init(int N, int X[], int Y[]) { time_start(); x.resize(N+1); y.resize(N); FOR(i,N) x[i] = X[i], y[i] = Y[i]; x[N] = 1; yseg.N = N; yseg.build(y); xsegd.N = N; xsegd.build(x); xsegm.N = N; xsegm.build(x); FOR(i,N){ if(x[i]>1) xx.insert(i); } xx.insert(N); xx.insert(0); time_end(); time_start(); get_ans(); time_end(); return get_ans(); } int cc=0; int updateX(int pos, int val) { cc++; if(x[pos]==val) return get_ans(); if(val==1 && x[pos]!=1) xx.erase(pos); else if(x[pos]==1 && val!=1) xx.insert(pos); x[pos] = val; xsegd.update(pos, x[pos]); xsegm.update(pos, x[pos]); int anss = get_ans(); return anss; } int updateY(int pos, int val) { cc++; yseg.update(pos, pos, val); y[pos] = val; int anss = get_ans(); return anss; }

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

horses.cpp:26:9: warning: inline variables are only available with '-std=c++17' or '-std=gnu++17'
   26 |  static inline int N;
      |         ^~~~~~
horses.cpp:100:9: warning: inline variables are only available with '-std=c++17' or '-std=gnu++17'
  100 |  static inline int N;
      |         ^~~~~~
horses.cpp:188:9: warning: inline variables are only available with '-std=c++17' or '-std=gnu++17'
  188 |  static inline int N;
      |         ^~~~~~
horses.cpp: In function 'void time_end()':
horses.cpp:276:7: warning: unused variable 'endt' [-Wunused-variable]
  276 |  auto endt = clock();
      |       ^~~~
horses.cpp: In function 'int get_ans()':
horses.cpp:322:50: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  322 |  c= ((ll) c * (ll) yseg.query(maxapos, next-1) ) %MOD;
      |                                                  ^
horses.cpp: In instantiation of 'void seg_tree<T>::create_children(int) [with T = int]':
horses.cpp:55:4:   required from 'void seg_tree<T>::build(std::vector<_Tp>&, int, int, int) [with T = int]'
horses.cpp:335:14:   required from here
horses.cpp:46:12: warning: conversion from 'std::vector<seg_tree<int>::node, std::allocator<seg_tree<int>::node> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   46 |    par.left=seg.size(), seg.push_back(node());
horses.cpp:48:30: warning: conversion from 'std::vector<seg_tree<int>::node, std::allocator<seg_tree<int>::node> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   48 |   if(par.right==-1) par.right=seg.size(), seg.push_back(node());
horses.cpp: In instantiation of 'void mult_seg_tree<T>::create_children(int) [with T = double]':
horses.cpp:141:4:   required from 'void mult_seg_tree<T>::build(std::vector<int>&, int, int, int) [with T = double]'
horses.cpp:338:15:   required from here
horses.cpp:132:12: warning: conversion from 'std::vector<mult_seg_tree<double>::node, std::allocator<mult_seg_tree<double>::node> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
  132 |    par.left=seg.size(), seg.push_back(node());
horses.cpp:134:30: warning: conversion from 'std::vector<mult_seg_tree<double>::node, std::allocator<mult_seg_tree<double>::node> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
  134 |   if(par.right==-1) par.right=seg.size(), seg.push_back(node());
horses.cpp: In instantiation of 'void mult_mod_seg_tree<T>::create_children(int) [with T = int]':
horses.cpp:229:4:   required from 'void mult_mod_seg_tree<T>::build(std::vector<_Tp>&, int, int, int) [with T = int]'
horses.cpp:341:15:   required from here
horses.cpp:220:12: warning: conversion from 'std::vector<mult_mod_seg_tree<int>::node, std::allocator<mult_mod_seg_tree<int>::node> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
  220 |    par.left=seg.size(), seg.push_back(node());
horses.cpp:222:30: warning: conversion from 'std::vector<mult_mod_seg_tree<int>::node, std::allocator<mult_mod_seg_tree<int>::node> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
  222 |   if(par.right==-1) par.right=seg.size(), seg.push_back(node());
horses.cpp: In instantiation of 'mult_mod_seg_tree<T>::node mult_mod_seg_tree<T>::merge(mult_mod_seg_tree<T>::node, mult_mod_seg_tree<T>::node, mult_mod_seg_tree<T>::node) [with T = int]':
horses.cpp:233:15:   required from 'void mult_mod_seg_tree<T>::build(std::vector<_Tp>&, int, int, int) [with T = int]'
horses.cpp:341:15:   required from here
horses.cpp:196:41: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  196 |   ret.val = (((ll)a.val * ((ll)b.val))) % MOD;
      |                                         ^
horses.cpp: In instantiation of 'void mult_seg_tree<T>::update_node(int, int, int, int) [with T = double]':
horses.cpp:150:22:   required from 'void mult_seg_tree<T>::update(int, int, int, int, int) [with T = double]'
horses.cpp:362:26:   required from here
horses.cpp:112:48: warning: unused parameter 'l' [-Wunused-parameter]
  112 |  inline void update_node(int ind, int val, int l, int r){
      |                                            ~~~~^
horses.cpp:112:55: warning: unused parameter 'r' [-Wunused-parameter]
  112 |  inline void update_node(int ind, int val, int l, int r){
      |                                                   ~~~~^
horses.cpp: In instantiation of 'void mult_seg_tree<T>::down(mult_seg_tree<T>::node&, int, int) [with T = double]':
horses.cpp:154:4:   required from 'void mult_seg_tree<T>::update(int, int, int, int, int) [with T = double]'
horses.cpp:362:26:   required from here
horses.cpp:116:25: warning: unused parameter 'par' [-Wunused-parameter]
  116 |  inline void down(node &par, int l, int r){
      |                   ~~~~~~^~~
horses.cpp:116:34: warning: unused parameter 'l' [-Wunused-parameter]
  116 |  inline void down(node &par, int l, int r){
      |                              ~~~~^
horses.cpp:116:41: warning: unused parameter 'r' [-Wunused-parameter]
  116 |  inline void down(node &par, int l, int r){
      |                                     ~~~~^
horses.cpp: In instantiation of 'void mult_mod_seg_tree<T>::update_node(int, int, int, int) [with T = int]':
horses.cpp:238:22:   required from 'void mult_mod_seg_tree<T>::update(int, int, int, int, int) [with T = int]'
horses.cpp:363:26:   required from here
horses.cpp:200:48: warning: unused parameter 'l' [-Wunused-parameter]
  200 |  inline void update_node(int ind, int val, int l, int r){
      |                                            ~~~~^
horses.cpp:200:55: warning: unused parameter 'r' [-Wunused-parameter]
  200 |  inline void update_node(int ind, int val, int l, int r){
      |                                                   ~~~~^
horses.cpp: In instantiation of 'void mult_mod_seg_tree<T>::down(mult_mod_seg_tree<T>::node&, int, int) [with T = int]':
horses.cpp:242:4:   required from 'void mult_mod_seg_tree<T>::update(int, int, int, int, int) [with T = int]'
horses.cpp:363:26:   required from here
horses.cpp:204:25: warning: unused parameter 'par' [-Wunused-parameter]
  204 |  inline void down(node &par, int l, int r){
      |                   ~~~~~~^~~
horses.cpp:204:34: warning: unused parameter 'l' [-Wunused-parameter]
  204 |  inline void down(node &par, int l, int r){
      |                              ~~~~^
horses.cpp:204:41: warning: unused parameter 'r' [-Wunused-parameter]
  204 |  inline void down(node &par, int l, int r){
      |                                     ~~~~^
horses.cpp: In instantiation of 'void seg_tree<T>::update_node(int, int, int, int) [with T = int]':
horses.cpp:64:22:   required from 'void seg_tree<T>::update(int, int, int, int, int, int) [with T = int]'
horses.cpp:370:27:   required from here
horses.cpp:38:48: warning: unused parameter 'l' [-Wunused-parameter]
   38 |  inline void update_node(int ind, int val, int l, int r){
      |                                            ~~~~^
horses.cpp:38:55: warning: unused parameter 'r' [-Wunused-parameter]
   38 |  inline void update_node(int ind, int val, int l, int r){
      |                                                   ~~~~^
#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...