답안 #639004

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
639004 2022-09-08T07:42:00 Z ghostwriter 말 (IOI15_horses) C++14
100 / 100
174 ms 46332 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#include "grader.cpp"
#endif
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
    Tran The Bao
    CTL - Da Lat
    Cay ngay cay dem nhung deo duoc cong nhan
*/
const int oo = 1e9 + 1;
const int M = 1e9 + 7;
const int MAXN = 5e5 + 1;
const int MAXT = 2e6 + 1;
struct Node {
	int pre, suf, x, y, pos, val;
	Node() {}
	Node(int pre, int suf, int x, int y, int pos, int val) : pre(pre), suf(suf), x(x), y(y), pos(pos), val(val) {}
};
int comp(ll x) { return min(x, 1LL * oo); }
Node comb(Node &a, Node &b) {
	Node ans;
	int newy = comp(1LL * comp(1LL * comp(1LL * a.suf * b.pre) * b.x) * b.y);
	if (a.y < newy) {
		ans.pre = comp(1LL * a.val * b.pre);
		ans.suf = b.suf;
		ans.x = b.x;
		ans.y = b.y;
		ans.pos = b.pos;
	}
	else {
		ans.pre = a.pre;
		ans.suf = comp(1LL * a.suf * b.val);
		ans.x = a.x;
		ans.y = a.y;
		ans.pos = a.pos;
	}
	ans.val = 1LL * a.val * b.val % M;
	return ans;
}
int N;
Node tr[MAXT];
pi a[MAXN];
void build(int i, int l, int r) {
	if (l == r) {
		tr[i] = Node(1, 1, a[l].st, a[l].nd, l, a[l].st);
		return;
	}
	int mid = l + (r - l) / 2;
	build(i * 2, l, mid);
	build(i * 2 + 1, mid + 1, r);
	tr[i] = comb(tr[i * 2], tr[i * 2 + 1]);
}
void upd(int i, int l, int r, int q) {
	if (r < q || l > q) return;
	if (l == r) {
		tr[i] = Node(1, 1, a[l].st, a[l].nd, l, a[l].st);
		return;
	}
	int mid = l + (r - l) / 2;
	upd(i * 2, l, mid, q);
	upd(i * 2 + 1, mid + 1, r, q);
	tr[i] = comb(tr[i * 2], tr[i * 2 + 1]);
}
int get(int i, int l, int r, int ql, int qr) {
	if (r < ql || l > qr) return 1;
	if (ql <= l && r <= qr) return tr[i].val;
	int mid = l + (r - l) / 2;
	return 1LL * get(i * 2, l, mid, ql, qr) * get(i * 2 + 1, mid + 1, r, ql, qr) % M;
}
int init(int N, int X[], int Y[]) {
	::N = N;
	FOR(i, 0, N - 1) a[i] = {X[i], Y[i]};
	build(1, 0, N - 1);
	int pos = tr[1].pos;
	return 1LL * get(1, 0, N - 1, 0, pos) * a[pos].nd % M;
}
int updateX(int pos, int val) {
	a[pos].st = val;
	upd(1, 0, N - 1, pos);
	int pos1 = tr[1].pos;
	return 1LL * get(1, 0, N - 1, 0, pos1) * a[pos1].nd % M;
}
int updateY(int pos, int val) {
	a[pos].nd = val;
	upd(1, 0, N - 1, pos);
	int pos1 = tr[1].pos;
	return 1LL * get(1, 0, N - 1, 0, pos1) * a[pos1].nd % M;
}

Compilation message

horses.cpp: In constructor 'Node::Node(int, int, int, int, int, int)':
horses.cpp:45:52: warning: declaration of 'val' shadows a member of 'Node' [-Wshadow]
   45 |  Node(int pre, int suf, int x, int y, int pos, int val) : pre(pre), suf(suf), x(x), y(y), pos(pos), val(val) {}
      |                                                ~~~~^~~
horses.cpp:43:27: note: shadowed declaration is here
   43 |  int pre, suf, x, y, pos, val;
      |                           ^~~
horses.cpp:45:43: warning: declaration of 'pos' shadows a member of 'Node' [-Wshadow]
   45 |  Node(int pre, int suf, int x, int y, int pos, int val) : pre(pre), suf(suf), x(x), y(y), pos(pos), val(val) {}
      |                                       ~~~~^~~
horses.cpp:43:22: note: shadowed declaration is here
   43 |  int pre, suf, x, y, pos, val;
      |                      ^~~
horses.cpp:45:36: warning: declaration of 'y' shadows a member of 'Node' [-Wshadow]
   45 |  Node(int pre, int suf, int x, int y, int pos, int val) : pre(pre), suf(suf), x(x), y(y), pos(pos), val(val) {}
      |                                ~~~~^
horses.cpp:43:19: note: shadowed declaration is here
   43 |  int pre, suf, x, y, pos, val;
      |                   ^
horses.cpp:45:29: warning: declaration of 'x' shadows a member of 'Node' [-Wshadow]
   45 |  Node(int pre, int suf, int x, int y, int pos, int val) : pre(pre), suf(suf), x(x), y(y), pos(pos), val(val) {}
      |                         ~~~~^
horses.cpp:43:16: note: shadowed declaration is here
   43 |  int pre, suf, x, y, pos, val;
      |                ^
horses.cpp:45:20: warning: declaration of 'suf' shadows a member of 'Node' [-Wshadow]
   45 |  Node(int pre, int suf, int x, int y, int pos, int val) : pre(pre), suf(suf), x(x), y(y), pos(pos), val(val) {}
      |                ~~~~^~~
horses.cpp:43:11: note: shadowed declaration is here
   43 |  int pre, suf, x, y, pos, val;
      |           ^~~
horses.cpp:45:11: warning: declaration of 'pre' shadows a member of 'Node' [-Wshadow]
   45 |  Node(int pre, int suf, int x, int y, int pos, int val) : pre(pre), suf(suf), x(x), y(y), pos(pos), val(val) {}
      |       ~~~~^~~
horses.cpp:43:6: note: shadowed declaration is here
   43 |  int pre, suf, x, y, pos, val;
      |      ^~~
horses.cpp: In constructor 'Node::Node(int, int, int, int, int, int)':
horses.cpp:45:52: warning: declaration of 'val' shadows a member of 'Node' [-Wshadow]
   45 |  Node(int pre, int suf, int x, int y, int pos, int val) : pre(pre), suf(suf), x(x), y(y), pos(pos), val(val) {}
      |                                                ~~~~^~~
horses.cpp:43:27: note: shadowed declaration is here
   43 |  int pre, suf, x, y, pos, val;
      |                           ^~~
horses.cpp:45:43: warning: declaration of 'pos' shadows a member of 'Node' [-Wshadow]
   45 |  Node(int pre, int suf, int x, int y, int pos, int val) : pre(pre), suf(suf), x(x), y(y), pos(pos), val(val) {}
      |                                       ~~~~^~~
horses.cpp:43:22: note: shadowed declaration is here
   43 |  int pre, suf, x, y, pos, val;
      |                      ^~~
horses.cpp:45:36: warning: declaration of 'y' shadows a member of 'Node' [-Wshadow]
   45 |  Node(int pre, int suf, int x, int y, int pos, int val) : pre(pre), suf(suf), x(x), y(y), pos(pos), val(val) {}
      |                                ~~~~^
horses.cpp:43:19: note: shadowed declaration is here
   43 |  int pre, suf, x, y, pos, val;
      |                   ^
horses.cpp:45:29: warning: declaration of 'x' shadows a member of 'Node' [-Wshadow]
   45 |  Node(int pre, int suf, int x, int y, int pos, int val) : pre(pre), suf(suf), x(x), y(y), pos(pos), val(val) {}
      |                         ~~~~^
horses.cpp:43:16: note: shadowed declaration is here
   43 |  int pre, suf, x, y, pos, val;
      |                ^
horses.cpp:45:20: warning: declaration of 'suf' shadows a member of 'Node' [-Wshadow]
   45 |  Node(int pre, int suf, int x, int y, int pos, int val) : pre(pre), suf(suf), x(x), y(y), pos(pos), val(val) {}
      |                ~~~~^~~
horses.cpp:43:11: note: shadowed declaration is here
   43 |  int pre, suf, x, y, pos, val;
      |           ^~~
horses.cpp:45:11: warning: declaration of 'pre' shadows a member of 'Node' [-Wshadow]
   45 |  Node(int pre, int suf, int x, int y, int pos, int val) : pre(pre), suf(suf), x(x), y(y), pos(pos), val(val) {}
      |       ~~~~^~~
horses.cpp:43:6: note: shadowed declaration is here
   43 |  int pre, suf, x, y, pos, val;
      |      ^~~
horses.cpp: In constructor 'Node::Node(int, int, int, int, int, int)':
horses.cpp:45:52: warning: declaration of 'val' shadows a member of 'Node' [-Wshadow]
   45 |  Node(int pre, int suf, int x, int y, int pos, int val) : pre(pre), suf(suf), x(x), y(y), pos(pos), val(val) {}
      |                                                ~~~~^~~
horses.cpp:43:27: note: shadowed declaration is here
   43 |  int pre, suf, x, y, pos, val;
      |                           ^~~
horses.cpp:45:43: warning: declaration of 'pos' shadows a member of 'Node' [-Wshadow]
   45 |  Node(int pre, int suf, int x, int y, int pos, int val) : pre(pre), suf(suf), x(x), y(y), pos(pos), val(val) {}
      |                                       ~~~~^~~
horses.cpp:43:22: note: shadowed declaration is here
   43 |  int pre, suf, x, y, pos, val;
      |                      ^~~
horses.cpp:45:36: warning: declaration of 'y' shadows a member of 'Node' [-Wshadow]
   45 |  Node(int pre, int suf, int x, int y, int pos, int val) : pre(pre), suf(suf), x(x), y(y), pos(pos), val(val) {}
      |                                ~~~~^
horses.cpp:43:19: note: shadowed declaration is here
   43 |  int pre, suf, x, y, pos, val;
      |                   ^
horses.cpp:45:29: warning: declaration of 'x' shadows a member of 'Node' [-Wshadow]
   45 |  Node(int pre, int suf, int x, int y, int pos, int val) : pre(pre), suf(suf), x(x), y(y), pos(pos), val(val) {}
      |                         ~~~~^
horses.cpp:43:16: note: shadowed declaration is here
   43 |  int pre, suf, x, y, pos, val;
      |                ^
horses.cpp:45:20: warning: declaration of 'suf' shadows a member of 'Node' [-Wshadow]
   45 |  Node(int pre, int suf, int x, int y, int pos, int val) : pre(pre), suf(suf), x(x), y(y), pos(pos), val(val) {}
      |                ~~~~^~~
horses.cpp:43:11: note: shadowed declaration is here
   43 |  int pre, suf, x, y, pos, val;
      |           ^~~
horses.cpp:45:11: warning: declaration of 'pre' shadows a member of 'Node' [-Wshadow]
   45 |  Node(int pre, int suf, int x, int y, int pos, int val) : pre(pre), suf(suf), x(x), y(y), pos(pos), val(val) {}
      |       ~~~~^~~
horses.cpp:43:6: note: shadowed declaration is here
   43 |  int pre, suf, x, y, pos, val;
      |      ^~~
horses.cpp: In function 'int comp(ll)':
horses.cpp:47:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   47 | int comp(ll x) { return min(x, 1LL * oo); }
      |                         ~~~^~~~~~~~~~~~~
horses.cpp: In function 'Node comb(Node&, Node&)':
horses.cpp:65:32: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   65 |  ans.val = 1LL * a.val * b.val % M;
      |            ~~~~~~~~~~~~~~~~~~~~^~~
horses.cpp: In function 'int get(int, int, int, int, int)':
horses.cpp:96:79: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   96 |  return 1LL * get(i * 2, l, mid, ql, qr) * get(i * 2 + 1, mid + 1, r, ql, qr) % M;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:98:14: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   98 | int init(int N, int X[], int Y[]) {
      |          ~~~~^
horses.cpp:68:5: note: shadowed declaration is here
   68 | int N;
      |     ^
horses.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
horses.cpp:100:2: note: in expansion of macro 'FOR'
  100 |  FOR(i, 0, N - 1) a[i] = {X[i], Y[i]};
      |  ^~~
horses.cpp:103:52: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  103 |  return 1LL * get(1, 0, N - 1, 0, pos) * a[pos].nd % M;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:109:54: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  109 |  return 1LL * get(1, 0, N - 1, 0, pos1) * a[pos1].nd % M;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:115:54: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  115 |  return 1LL * get(1, 0, N - 1, 0, pos1) * a[pos1].nd % M;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 316 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 320 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 37464 KB Output is correct
2 Correct 158 ms 46332 KB Output is correct
3 Correct 126 ms 37452 KB Output is correct
4 Correct 166 ms 41320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 54 ms 36752 KB Output is correct
34 Correct 54 ms 36792 KB Output is correct
35 Correct 71 ms 43640 KB Output is correct
36 Correct 75 ms 43564 KB Output is correct
37 Correct 42 ms 34896 KB Output is correct
38 Correct 44 ms 35772 KB Output is correct
39 Correct 37 ms 34824 KB Output is correct
40 Correct 61 ms 38776 KB Output is correct
41 Correct 38 ms 34824 KB Output is correct
42 Correct 43 ms 35020 KB Output is correct
43 Correct 53 ms 39068 KB Output is correct
44 Correct 51 ms 39096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 216 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 396 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 324 KB Output is correct
33 Correct 109 ms 37528 KB Output is correct
34 Correct 170 ms 46284 KB Output is correct
35 Correct 128 ms 37436 KB Output is correct
36 Correct 171 ms 41388 KB Output is correct
37 Correct 55 ms 36688 KB Output is correct
38 Correct 52 ms 36692 KB Output is correct
39 Correct 82 ms 43732 KB Output is correct
40 Correct 77 ms 43672 KB Output is correct
41 Correct 46 ms 34880 KB Output is correct
42 Correct 48 ms 35808 KB Output is correct
43 Correct 41 ms 34832 KB Output is correct
44 Correct 60 ms 38748 KB Output is correct
45 Correct 40 ms 34776 KB Output is correct
46 Correct 40 ms 34948 KB Output is correct
47 Correct 54 ms 39104 KB Output is correct
48 Correct 51 ms 39124 KB Output is correct
49 Correct 174 ms 38700 KB Output is correct
50 Correct 150 ms 38704 KB Output is correct
51 Correct 156 ms 45532 KB Output is correct
52 Correct 133 ms 45104 KB Output is correct
53 Correct 148 ms 37140 KB Output is correct
54 Correct 119 ms 37588 KB Output is correct
55 Correct 112 ms 35948 KB Output is correct
56 Correct 125 ms 40524 KB Output is correct
57 Correct 107 ms 36428 KB Output is correct
58 Correct 104 ms 37000 KB Output is correct
59 Correct 49 ms 39112 KB Output is correct