제출 #1197903

#제출 시각아이디문제언어결과실행 시간메모리
1197903haitax511Horses (IOI15_horses)C++20
컴파일 에러
0 ms0 KiB
#define p(i,n) for(int i=0; i<n; i++) #define rp(i,n) for(int i=n-1; i>=0; i--) #define grid_int vector<vector<int>> #define grid_char vector<vector<char>> void ADD(int& c,int a, int b, int m) {c = ((a % m) + (b % m)) % m;return;} void MUL(int& c,int a, int b, int m) {c = ((a % m) * (b % m)) % m;} void SUB(int& c,int a, int b, int m) {c = ((a % m) - (b % m) + m) % m;} void MIN(int& a, int b) {a = min(a, b);} void MAX(int& a, int b) {a = max(a, b);} int gcdExtended(int a, int b, int *x, int *y); int modInverse(int b, int m){int x,y;int g = gcdExtended(b, m, &x, &y);if (g != 1)return -1;return (x%m + m) % m;} int modDivide(int a, int b, int m){a = a % m;int inv = modInverse(b, m);return (inv * a) % m;} int gcdExtended(int a, int b, int *x, int *y){if (a == 0){*x = 0, *y = 1;return b;}int x1, y1;int gcd = gcdExtended(b%a, a, &x1, &y1);*x = y1 - (b/a) * x1;*y = x1;return gcd;} #define f first #define s second #define ll long long #define pb push_back//SEGGY FOR max pref sum; vector<int> xi, yi; int nnn; struct item { double lg; int idx; int val; // VAL IS THE XI // LG IS LOG OF SELLING AT DAY index // iDX IS INDEX }; struct segtree { vector<item> seggy; vector<double> lazy; int n; segtree(int _n) { n = _n; seggy.resize(4 * n); lazy.resize(4 * n, 0); } item merge(item a, item b) { item x; if (a.lg > b.lg) { x.lg = a.lg; x.idx = a.idx; } else { x.lg = b.lg; x.idx = b.idx; } MUL(x.val, a.val, b.val, MOD); return x; } void push(int node, int left, int right) { if (lazy[node] != 0) { seggy[node].lg += lazy[node]; if (left != right) { lazy[2 * node] += lazy[node]; lazy[2 * node + 1] += lazy[node]; } lazy[node] = 0; } } void build(int node, int left, int right) { if (left == right) { seggy[node].idx = left; seggy[node].lg = log(yi[left]); seggy[node].val = xi[left]; } else { int mid = (left + right) / 2; build(2 * node, left, mid); build(2 * node + 1, mid + 1, right); seggy[node] = merge(seggy[2 * node], seggy[2 * node + 1]); } } // Point update to set new value and log void update(int node, int left, int right, int idx, int vv) { push(node, left, right); if (left == right) { seggy[node].idx = left; seggy[node].lg = log(vv); seggy[node].val = vv; } else { int mid = (left + right) / 2; if (idx > mid) update(2 * node + 1, mid + 1, right, idx, vv); else update(2 * node, left, mid, idx, vv); seggy[node] = merge(seggy[2 * node], seggy[2 * node + 1]); } } // Point update to add value to lg void update_lg(int node, int left, int right, int idx, double vv) { if (left == right) { seggy[node].idx = left; seggy[node].lg += vv; return; } int mid = (left + right) / 2; if (idx > mid) update_lg(2 * node + 1, mid + 1, right, idx, vv); else update_lg(2 * node, left, mid, idx, vv); seggy[node] = merge(seggy[2 * node], seggy[2 * node + 1]); } // New range update function for .lg using lazy propagation void lazyx(int node, int left, int right, int l, int r, double add_val) { push(node, left, right); if (r < left || l > right) return; if (l <= left && right <= r) { lazy[node] += add_val; push(node, left, right); return; } int mid = (left + right) / 2; lazyx(2 * node, left, mid, l, r, add_val); lazyx(2 * node + 1, mid + 1, right, l, r, add_val); seggy[node] = merge(seggy[2 * node], seggy[2 * node + 1]); } int query(int node, int left, int right, int l, int r) { push(node, left, right); if (l > right || r < left) return 1; if (left >= l && right <= r) return seggy[node].val % MOD; int mid = (left + right) / 2; int xx = query(2 * node, left, mid, l, r); int yy = query(2 * node + 1, mid + 1, right, l, r); int temp; MUL(temp, xx, yy, MOD); return temp; } item grab() { return seggy[1]; // root is usually at index 1 } }; segtree Tree(2e6+200); int opt(vector<int>& a, vector<int>& b, int n) { item x = Tree.grab(); int ppp = Tree.query(1, 0, nnn - 1, 0, x.idx); int temp; MUL(temp, ppp, yi[x.idx], MOD); return temp; } // the functions that are asked by the grader int init(int n, int X[], int Y[]) { nnn = n; xi.resize(nnn); yi.resize(nnn); for (int i = 0; i < n; i++) { xi[i] = X[i]; Tree.lazyx(1,0,n-1,i,n-1,log(xi[i])); } for (int i = 0; i < n; i++) yi[i] = Y[i]; Tree.build(1,0,n-1); return opt(xi, yi, n); } int updateX(int pos, int val) { Tree.update_lg(1, 0, nnn - 1, pos, log(val) - log(xi[pos])); xi[pos] = val; Tree.update(1, 0, nnn - 1, pos, val); return opt(xi, yi, nnn); } int updateY(int pos, int val) { Tree.update_lg(1, 0, nnn - 1, pos, log(val) - log(yi[pos])); yi[pos] = val; return opt(xi, yi, nnn); }

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

horses.cpp: In function 'void MIN(int&, int)':
horses.cpp:8:30: error: 'min' was not declared in this scope
    8 | void MIN(int& a, int b) {a = min(a, b);}
      |                              ^~~
horses.cpp: In function 'void MAX(int&, int)':
horses.cpp:9:30: error: 'max' was not declared in this scope
    9 | void MAX(int& a, int b) {a = max(a, b);}
      |                              ^~~
horses.cpp: At global scope:
horses.cpp:18:1: error: 'vector' does not name a type
   18 | vector<int> xi, yi;
      | ^~~~~~
horses.cpp:31:5: error: 'vector' does not name a type
   31 |     vector<item> seggy;
      |     ^~~~~~
horses.cpp:32:5: error: 'vector' does not name a type
   32 |     vector<double> lazy;
      |     ^~~~~~
horses.cpp: In constructor 'segtree::segtree(int)':
horses.cpp:37:9: error: 'seggy' was not declared in this scope
   37 |         seggy.resize(4 * n);
      |         ^~~~~
horses.cpp:38:9: error: 'lazy' was not declared in this scope; did you mean 'lazyx'?
   38 |         lazy.resize(4 * n, 0);
      |         ^~~~
      |         lazyx
horses.cpp: In member function 'item segtree::merge(item, item)':
horses.cpp:50:34: error: 'MOD' was not declared in this scope
   50 |         MUL(x.val, a.val, b.val, MOD);
      |                                  ^~~
horses.cpp: In member function 'void segtree::push(int, int, int)':
horses.cpp:55:13: error: 'lazy' was not declared in this scope; did you mean 'lazyx'?
   55 |         if (lazy[node] != 0) {
      |             ^~~~
      |             lazyx
horses.cpp:56:13: error: 'seggy' was not declared in this scope
   56 |             seggy[node].lg += lazy[node];
      |             ^~~~~
horses.cpp: In member function 'void segtree::build(int, int, int)':
horses.cpp:67:13: error: 'seggy' was not declared in this scope
   67 |             seggy[node].idx = left;
      |             ^~~~~
horses.cpp:68:34: error: 'yi' was not declared in this scope
   68 |             seggy[node].lg = log(yi[left]);
      |                                  ^~
horses.cpp:68:30: error: 'log' was not declared in this scope; did you mean 'long'?
   68 |             seggy[node].lg = log(yi[left]);
      |                              ^~~
      |                              long
horses.cpp:69:31: error: 'xi' was not declared in this scope
   69 |             seggy[node].val = xi[left];
      |                               ^~
horses.cpp:74:13: error: 'seggy' was not declared in this scope
   74 |             seggy[node] = merge(seggy[2 * node], seggy[2 * node + 1]);
      |             ^~~~~
horses.cpp: In member function 'void segtree::update(int, int, int, int, int)':
horses.cpp:82:13: error: 'seggy' was not declared in this scope
   82 |             seggy[node].idx = left;
      |             ^~~~~
horses.cpp:83:30: error: 'log' was not declared in this scope; did you mean 'long'?
   83 |             seggy[node].lg = log(vv);
      |                              ^~~
      |                              long
horses.cpp:89:13: error: 'seggy' was not declared in this scope
   89 |             seggy[node] = merge(seggy[2 * node], seggy[2 * node + 1]);
      |             ^~~~~
horses.cpp: In member function 'void segtree::update_lg(int, int, int, int, double)':
horses.cpp:96:13: error: 'seggy' was not declared in this scope
   96 |             seggy[node].idx = left;
      |             ^~~~~
horses.cpp:103:9: error: 'seggy' was not declared in this scope
  103 |         seggy[node] = merge(seggy[2 * node], seggy[2 * node + 1]);
      |         ^~~~~
horses.cpp: In member function 'void segtree::lazyx(int, int, int, int, int, double)':
horses.cpp:112:13: error: 'lazy' was not declared in this scope; did you mean 'lazyx'?
  112 |             lazy[node] += add_val;
      |             ^~~~
      |             lazyx
horses.cpp:120:9: error: 'seggy' was not declared in this scope
  120 |         seggy[node] = merge(seggy[2 * node], seggy[2 * node + 1]);
      |         ^~~~~
horses.cpp: In member function 'int segtree::query(int, int, int, int, int)':
horses.cpp:126:45: error: 'seggy' was not declared in this scope
  126 |         if (left >= l && right <= r) return seggy[node].val % MOD;
      |                                             ^~~~~
horses.cpp:126:63: error: 'MOD' was not declared in this scope
  126 |         if (left >= l && right <= r) return seggy[node].val % MOD;
      |                                                               ^~~
horses.cpp:132:27: error: 'MOD' was not declared in this scope
  132 |         MUL(temp, xx, yy, MOD);
      |                           ^~~
horses.cpp: In member function 'item segtree::grab()':
horses.cpp:137:16: error: 'seggy' was not declared in this scope
  137 |         return seggy[1]; // root is usually at index 1
      |                ^~~~~
horses.cpp: At global scope:
horses.cpp:142:9: error: 'vector' was not declared in this scope
  142 | int opt(vector<int>& a, vector<int>& b, int n) {
      |         ^~~~~~
horses.cpp:142:16: error: expected primary-expression before 'int'
  142 | int opt(vector<int>& a, vector<int>& b, int n) {
      |                ^~~
horses.cpp:142:25: error: 'vector' was not declared in this scope
  142 | int opt(vector<int>& a, vector<int>& b, int n) {
      |                         ^~~~~~
horses.cpp:142:32: error: expected primary-expression before 'int'
  142 | int opt(vector<int>& a, vector<int>& b, int n) {
      |                                ^~~
horses.cpp:142:41: error: expected primary-expression before 'int'
  142 | int opt(vector<int>& a, vector<int>& b, int n) {
      |                                         ^~~
horses.cpp:142:46: error: expression list treated as compound expression in initializer [-fpermissive]
  142 | int opt(vector<int>& a, vector<int>& b, int n) {
      |                                              ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:153:5: error: 'xi' was not declared in this scope
  153 |     xi.resize(nnn);
      |     ^~
horses.cpp:154:5: error: 'yi' was not declared in this scope
  154 |     yi.resize(nnn);
      |     ^~
horses.cpp:157:34: error: 'log' was not declared in this scope; did you mean 'long'?
  157 |         Tree.lazyx(1,0,n-1,i,n-1,log(xi[i]));
      |                                  ^~~
      |                                  long
horses.cpp:162:15: error: 'opt' cannot be used as a function
  162 |     return opt(xi, yi, n);
      |            ~~~^~~~~~~~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:166:40: error: 'log' was not declared in this scope; did you mean 'long'?
  166 |     Tree.update_lg(1, 0, nnn - 1, pos, log(val) - log(xi[pos]));
      |                                        ^~~
      |                                        long
horses.cpp:166:55: error: 'xi' was not declared in this scope
  166 |     Tree.update_lg(1, 0, nnn - 1, pos, log(val) - log(xi[pos]));
      |                                                       ^~
horses.cpp:171:20: error: 'yi' was not declared in this scope
  171 |     return opt(xi, yi, nnn);
      |                    ^~
horses.cpp:171:15: error: 'opt' cannot be used as a function
  171 |     return opt(xi, yi, nnn);
      |            ~~~^~~~~~~~~~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:175:40: error: 'log' was not declared in this scope; did you mean 'long'?
  175 |     Tree.update_lg(1, 0, nnn - 1, pos, log(val) - log(yi[pos]));
      |                                        ^~~
      |                                        long
horses.cpp:175:55: error: 'yi' was not declared in this scope
  175 |     Tree.update_lg(1, 0, nnn - 1, pos, log(val) - log(yi[pos]));
      |                                                       ^~
horses.cpp:178:16: error: 'xi' was not declared in this scope
  178 |     return opt(xi, yi, nnn);
      |                ^~
horses.cpp:178:15: error: 'opt' cannot be used as a function
  178 |     return opt(xi, yi, nnn);
      |            ~~~^~~~~~~~~~~~~