Submission #283292

#TimeUsernameProblemLanguageResultExecution timeMemory
283292stoyan_malininHorses (IOI15_horses)C++14
34 / 100
34 ms15488 KiB
#include "horses.h" //#include "grader.cpp" #include <cmath> #include <vector> #include <iostream> using namespace std; const int MAXN = 1e5 + 5; const long long mod = 1e9 + 7; int n; double lnPref[MAXN]; int x[MAXN], y[MAXN]; struct NodeInfo { int bestInd; double val, lazy; long long product; NodeInfo(){} NodeInfo(int x, double val, int ind) { this->product = x%mod; this->bestInd = ind; this->val = val; this->lazy = 0; } }; NodeInfo Merge(NodeInfo A, NodeInfo B) { NodeInfo C; C.lazy = 0; if(A.val<B.val) swap(A, B); C.val = A.val;C.bestInd = A.bestInd; C.product = (A.product*B.product)%mod; return C; } struct SegmentTree { NodeInfo info; int l, r; SegmentTree *L, *R; SegmentTree(){} SegmentTree(int l, int r) { this->l = l; this->r = r; this->L = nullptr; this->R = nullptr; } void build() { if(l==r) { this->info = NodeInfo(x[l], lnPref[l]+log(y[l]), l); return; } L = new SegmentTree(l, (l+r)/2); R = new SegmentTree((l+r)/2+1, r); L->build(); R->build(); info = Merge(L->info, R->info); } void updateLazy() { info.val += info.lazy; if(l!=r) { L->info.lazy += info.lazy; R->info.lazy += info.lazy; } info.lazy = 0; } void updateVal(int ql, int qr, double change) { updateLazy(); if(l>=ql && r<=qr) { info.val += change; if(l!=r) { L->info.lazy += change; R->info.lazy += change; } return; } if(r<ql || l>qr) return; L->updateVal(ql, qr, change); R->updateVal(ql, qr, change); info = Merge(L->info, R->info); } void updateProduct(int q, int newVal) { updateLazy(); if(l==r && l==q) { info.product = newVal; return; } if(r<q || l>q) return; L->updateProduct(q, newVal); R->updateProduct(q, newVal); info = Merge(L->info, R->info); } long long queryProduct(int ql, int qr) { updateLazy(); if(l>=ql && r<=qr) return info.product; if(r<ql || l>qr) return 1; return (L->queryProduct(ql, qr)*R->queryProduct(ql, qr))%mod; } void print() { cout << l << " " << r << " -> " << info.val << " " << info.bestInd << '\n'; if(l!=r) { L->print(); R->print(); } } }; SegmentTree *T; long long evalInd(int ind) { long long ans = T->queryProduct(0, ind); return (ans*y[ind])%mod; } int init(int N, int X[], int Y[]) { n = N; for(int i = 0;i<n;i++) { x[i] = X[i]; y[i] = Y[i]; } lnPref[0] = log(x[0]); for(int i = 1;i<n;i++) lnPref[i] = lnPref[i-1] + log(x[i]); T = new SegmentTree(0, n-1); T->build(); //T->print(); return evalInd(T->info.bestInd); } int updateX(int pos, int val) { double change = log(val) - log(x[pos]); x[pos] = val; T->updateVal(pos, n-1, change); T->updateProduct(pos, x[pos]); return evalInd(T->info.bestInd); } int updateY(int pos, int val) { double change = log(val) - log(y[pos]); y[pos] = val; T->updateVal(pos, pos, change); //cout << T->info.bestInd << " " << change << '\n'; //T->print(); return evalInd(T->info.bestInd); }

Compilation message (stderr)

horses.cpp: In constructor 'NodeInfo::NodeInfo(int, double, int)':
horses.cpp:25:5: warning: declaration of 'val' shadows a member of 'NodeInfo' [-Wshadow]
   25 |     {
      |     ^
horses.cpp:20:12: note: shadowed declaration is here
   20 |     double val, lazy;
      |            ^~~
horses.cpp:25:5: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   25 |     {
      |     ^
horses.cpp:15:5: note: shadowed declaration is here
   15 | int x[MAXN], y[MAXN];
      |     ^
horses.cpp: In constructor 'NodeInfo::NodeInfo(int, double, int)':
horses.cpp:30:5: warning: declaration of 'val' shadows a member of 'NodeInfo' [-Wshadow]
   30 |     }
      |     ^
horses.cpp:20:12: note: shadowed declaration is here
   20 |     double val, lazy;
      |            ^~~
horses.cpp:30:5: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   30 |     }
      |     ^
horses.cpp:15:5: note: shadowed declaration is here
   15 | int x[MAXN], y[MAXN];
      |     ^
horses.cpp: In constructor 'NodeInfo::NodeInfo(int, double, int)':
horses.cpp:30:5: warning: declaration of 'val' shadows a member of 'NodeInfo' [-Wshadow]
   30 |     }
      |     ^
horses.cpp:20:12: note: shadowed declaration is here
   20 |     double val, lazy;
      |            ^~~
horses.cpp:30:5: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   30 |     }
      |     ^
horses.cpp:15:5: note: shadowed declaration is here
   15 | int x[MAXN], y[MAXN];
      |     ^
horses.cpp: In constructor 'SegmentTree::SegmentTree(int, int)':
horses.cpp:55:5: warning: declaration of 'r' shadows a member of 'SegmentTree' [-Wshadow]
   55 |     {
      |     ^
horses.cpp:50:12: note: shadowed declaration is here
   50 |     int l, r;
      |            ^
horses.cpp:55:5: warning: declaration of 'l' shadows a member of 'SegmentTree' [-Wshadow]
   55 |     {
      |     ^
horses.cpp:50:9: note: shadowed declaration is here
   50 |     int l, r;
      |         ^
horses.cpp: In constructor 'SegmentTree::SegmentTree(int, int)':
horses.cpp:61:5: warning: declaration of 'r' shadows a member of 'SegmentTree' [-Wshadow]
   61 |     }
      |     ^
horses.cpp:50:12: note: shadowed declaration is here
   50 |     int l, r;
      |            ^
horses.cpp:61:5: warning: declaration of 'l' shadows a member of 'SegmentTree' [-Wshadow]
   61 |     }
      |     ^
horses.cpp:50:9: note: shadowed declaration is here
   50 |     int l, r;
      |         ^
horses.cpp: In constructor 'SegmentTree::SegmentTree(int, int)':
horses.cpp:61:5: warning: declaration of 'r' shadows a member of 'SegmentTree' [-Wshadow]
   61 |     }
      |     ^
horses.cpp:50:12: note: shadowed declaration is here
   50 |     int l, r;
      |            ^
horses.cpp:61:5: warning: declaration of 'l' shadows a member of 'SegmentTree' [-Wshadow]
   61 |     }
      |     ^
horses.cpp:50:9: note: shadowed declaration is here
   50 |     int l, r;
      |         ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:175:19: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  175 |     return evalInd(T->info.bestInd);
      |            ~~~~~~~^~~~~~~~~~~~~~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:186:19: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  186 |     return evalInd(T->info.bestInd);
      |            ~~~~~~~^~~~~~~~~~~~~~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:199:19: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  199 |     return evalInd(T->info.bestInd);
      |            ~~~~~~~^~~~~~~~~~~~~~~~~
#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...