Submission #41874

# Submission time Handle Problem Language Result Execution time Memory
41874 2018-02-22T03:09:22 Z funcsr Horses (IOI15_horses) C++14
100 / 100
376 ms 263672 KB
#include "horses.h"
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define pb push_back
#define _1 first
#define _2 second
#define INF 1145141919
#define MOD 1000000007

struct Node {
  int b, ans, l, r, p;
  Node (int b, int ans, int l, int r, int p) : b(b), ans(ans), l(l), r(r), p(p) {}
  Node () : b(0), ans(0), l(1), r(1), p(1) {}
};
inline int prod(int x, int y) { return min(1LL*x*y, (long long)INF); }
Node op(const Node &x, const Node &y) {
  if (x.b < prod(prod(y.l, x.r), y.b)) {
    return Node(y.b, (1LL*x.p*y.ans)%MOD, prod(prod(x.l, x.r), y.l), y.r, (1LL*x.p*y.p)%MOD);
  }
  else {
    return Node(x.b, x.ans, x.l, prod(x.r, prod(y.l, y.r)), (1LL*x.p*y.p)%MOD);
  }
}
#define MAX_N (1<<19)
Node seg[MAX_N*2-1];
void update(int k, Node v) {
  k += MAX_N-1;
  seg[k] = v;
  while (k > 0) {
    k = (k-1)/2;
    seg[k] = op(seg[k*2+1], seg[k*2+2]);
  }
}

int N;
int X[500000], Y[500000];
int init(int NN, int XX[], int YY[]) {
  N = NN;
  rep(i, N) X[i] = XX[i], Y[i] = YY[i];
  rep(i, N) update(i, Node(Y[i], (1LL*X[i]*Y[i])%MOD, X[i], 1, X[i]));
  return seg[0].ans;
}

int updateX(int pos, int val) {
  X[pos] = val;
  update(pos, Node(Y[pos], (1LL*X[pos]*Y[pos])%MOD, X[pos], 1, X[pos]));
  return seg[0].ans;
}

int updateY(int pos, int val) {
  Y[pos] = val;
  update(pos, Node(Y[pos], (1LL*X[pos]*Y[pos])%MOD, X[pos], 1, X[pos]));
  return seg[0].ans;
}

Compilation message

horses.cpp: In constructor 'Node::Node(int, int, int, int, int)':
horses.cpp:17:46: warning: declaration of 'p' shadows a member of 'Node' [-Wshadow]
   Node (int b, int ans, int l, int r, int p) : b(b), ans(ans), l(l), r(r), p(p) {}
                                              ^
horses.cpp:16:21: note: shadowed declaration is here
   int b, ans, l, r, p;
                     ^
horses.cpp:17:46: warning: declaration of 'r' shadows a member of 'Node' [-Wshadow]
   Node (int b, int ans, int l, int r, int p) : b(b), ans(ans), l(l), r(r), p(p) {}
                                              ^
horses.cpp:16:18: note: shadowed declaration is here
   int b, ans, l, r, p;
                  ^
horses.cpp:17:46: warning: declaration of 'l' shadows a member of 'Node' [-Wshadow]
   Node (int b, int ans, int l, int r, int p) : b(b), ans(ans), l(l), r(r), p(p) {}
                                              ^
horses.cpp:16:15: note: shadowed declaration is here
   int b, ans, l, r, p;
               ^
horses.cpp:17:46: warning: declaration of 'ans' shadows a member of 'Node' [-Wshadow]
   Node (int b, int ans, int l, int r, int p) : b(b), ans(ans), l(l), r(r), p(p) {}
                                              ^
horses.cpp:16:10: note: shadowed declaration is here
   int b, ans, l, r, p;
          ^
horses.cpp:17:46: warning: declaration of 'b' shadows a member of 'Node' [-Wshadow]
   Node (int b, int ans, int l, int r, int p) : b(b), ans(ans), l(l), r(r), p(p) {}
                                              ^
horses.cpp:16:7: note: shadowed declaration is here
   int b, ans, l, r, p;
       ^
horses.cpp: In function 'int prod(int, int)':
horses.cpp:20:67: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
 inline int prod(int x, int y) { return min(1LL*x*y, (long long)INF); }
                                                                   ^
horses.cpp: In function 'Node op(const Node&, const Node&)':
horses.cpp:23:92: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return Node(y.b, (1LL*x.p*y.ans)%MOD, prod(prod(x.l, x.r), y.l), y.r, (1LL*x.p*y.p)%MOD);
                                                                                            ^
horses.cpp:23:92: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
horses.cpp:26:78: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return Node(x.b, x.ans, x.l, prod(x.r, prod(y.l, y.r)), (1LL*x.p*y.p)%MOD);
                                                                              ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:45:68: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
   rep(i, N) update(i, Node(Y[i], (1LL*X[i]*Y[i])%MOD, X[i], 1, X[i]));
                                                                    ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:51:70: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
   update(pos, Node(Y[pos], (1LL*X[pos]*Y[pos])%MOD, X[pos], 1, X[pos]));
                                                                      ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:57:70: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
   update(pos, Node(Y[pos], (1LL*X[pos]*Y[pos])%MOD, X[pos], 1, X[pos]));
                                                                      ^
# Verdict Execution time Memory Grader output
1 Correct 16 ms 20856 KB Output is correct
2 Correct 16 ms 20856 KB Output is correct
3 Correct 16 ms 20904 KB Output is correct
4 Correct 15 ms 20920 KB Output is correct
5 Correct 16 ms 20956 KB Output is correct
6 Correct 16 ms 21008 KB Output is correct
7 Correct 16 ms 21028 KB Output is correct
8 Correct 16 ms 21028 KB Output is correct
9 Correct 16 ms 21208 KB Output is correct
10 Correct 16 ms 21208 KB Output is correct
11 Correct 16 ms 21212 KB Output is correct
12 Correct 16 ms 21212 KB Output is correct
13 Correct 16 ms 21212 KB Output is correct
14 Correct 16 ms 21212 KB Output is correct
15 Correct 18 ms 21212 KB Output is correct
16 Correct 16 ms 21212 KB Output is correct
17 Correct 16 ms 21212 KB Output is correct
18 Correct 16 ms 21212 KB Output is correct
19 Correct 17 ms 21212 KB Output is correct
20 Correct 17 ms 21212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 21212 KB Output is correct
2 Correct 16 ms 21212 KB Output is correct
3 Correct 17 ms 21212 KB Output is correct
4 Correct 17 ms 21212 KB Output is correct
5 Correct 18 ms 21212 KB Output is correct
6 Correct 16 ms 21212 KB Output is correct
7 Correct 17 ms 21212 KB Output is correct
8 Correct 16 ms 21212 KB Output is correct
9 Correct 16 ms 21212 KB Output is correct
10 Correct 16 ms 21212 KB Output is correct
11 Correct 17 ms 21212 KB Output is correct
12 Correct 17 ms 21212 KB Output is correct
13 Correct 17 ms 21212 KB Output is correct
14 Correct 17 ms 21212 KB Output is correct
15 Correct 17 ms 21212 KB Output is correct
16 Correct 21 ms 21212 KB Output is correct
17 Correct 21 ms 21212 KB Output is correct
18 Correct 16 ms 21212 KB Output is correct
19 Correct 16 ms 21212 KB Output is correct
20 Correct 20 ms 21212 KB Output is correct
21 Correct 18 ms 21212 KB Output is correct
22 Correct 16 ms 21228 KB Output is correct
23 Correct 17 ms 21228 KB Output is correct
24 Correct 17 ms 21300 KB Output is correct
25 Correct 17 ms 21300 KB Output is correct
26 Correct 17 ms 21300 KB Output is correct
27 Correct 17 ms 21320 KB Output is correct
28 Correct 18 ms 21384 KB Output is correct
29 Correct 17 ms 21384 KB Output is correct
30 Correct 17 ms 21384 KB Output is correct
31 Correct 17 ms 21444 KB Output is correct
32 Correct 17 ms 21444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 291 ms 30352 KB Output is correct
2 Correct 365 ms 42896 KB Output is correct
3 Correct 334 ms 46716 KB Output is correct
4 Correct 339 ms 54208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 54208 KB Output is correct
2 Correct 17 ms 54208 KB Output is correct
3 Correct 18 ms 54208 KB Output is correct
4 Correct 17 ms 54208 KB Output is correct
5 Correct 17 ms 54208 KB Output is correct
6 Correct 17 ms 54208 KB Output is correct
7 Correct 17 ms 54208 KB Output is correct
8 Correct 17 ms 54208 KB Output is correct
9 Correct 16 ms 54208 KB Output is correct
10 Correct 16 ms 54208 KB Output is correct
11 Correct 17 ms 54208 KB Output is correct
12 Correct 18 ms 54208 KB Output is correct
13 Correct 16 ms 54208 KB Output is correct
14 Correct 16 ms 54208 KB Output is correct
15 Correct 16 ms 54208 KB Output is correct
16 Correct 16 ms 54208 KB Output is correct
17 Correct 16 ms 54208 KB Output is correct
18 Correct 16 ms 54208 KB Output is correct
19 Correct 19 ms 54208 KB Output is correct
20 Correct 17 ms 54208 KB Output is correct
21 Correct 16 ms 54208 KB Output is correct
22 Correct 16 ms 54208 KB Output is correct
23 Correct 19 ms 54208 KB Output is correct
24 Correct 17 ms 54208 KB Output is correct
25 Correct 17 ms 54208 KB Output is correct
26 Correct 18 ms 54208 KB Output is correct
27 Correct 17 ms 54208 KB Output is correct
28 Correct 17 ms 54208 KB Output is correct
29 Correct 17 ms 54208 KB Output is correct
30 Correct 17 ms 54208 KB Output is correct
31 Correct 17 ms 54208 KB Output is correct
32 Correct 18 ms 54208 KB Output is correct
33 Correct 231 ms 57576 KB Output is correct
34 Correct 232 ms 61480 KB Output is correct
35 Correct 281 ms 72480 KB Output is correct
36 Correct 293 ms 83220 KB Output is correct
37 Correct 238 ms 85240 KB Output is correct
38 Correct 253 ms 88364 KB Output is correct
39 Correct 209 ms 90300 KB Output is correct
40 Correct 268 ms 96260 KB Output is correct
41 Correct 212 ms 98340 KB Output is correct
42 Correct 215 ms 100444 KB Output is correct
43 Correct 267 ms 106640 KB Output is correct
44 Correct 266 ms 113016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 113016 KB Output is correct
2 Correct 17 ms 113016 KB Output is correct
3 Correct 17 ms 113016 KB Output is correct
4 Correct 17 ms 113016 KB Output is correct
5 Correct 17 ms 113016 KB Output is correct
6 Correct 17 ms 113016 KB Output is correct
7 Correct 18 ms 113016 KB Output is correct
8 Correct 17 ms 113016 KB Output is correct
9 Correct 17 ms 113016 KB Output is correct
10 Correct 18 ms 113016 KB Output is correct
11 Correct 17 ms 113016 KB Output is correct
12 Correct 18 ms 113016 KB Output is correct
13 Correct 17 ms 113016 KB Output is correct
14 Correct 16 ms 113016 KB Output is correct
15 Correct 18 ms 113016 KB Output is correct
16 Correct 16 ms 113016 KB Output is correct
17 Correct 20 ms 113016 KB Output is correct
18 Correct 20 ms 113016 KB Output is correct
19 Correct 16 ms 113016 KB Output is correct
20 Correct 17 ms 113016 KB Output is correct
21 Correct 17 ms 113016 KB Output is correct
22 Correct 17 ms 113016 KB Output is correct
23 Correct 17 ms 113016 KB Output is correct
24 Correct 18 ms 113016 KB Output is correct
25 Correct 19 ms 113016 KB Output is correct
26 Correct 18 ms 113016 KB Output is correct
27 Correct 17 ms 113016 KB Output is correct
28 Correct 19 ms 113016 KB Output is correct
29 Correct 18 ms 113016 KB Output is correct
30 Correct 17 ms 113016 KB Output is correct
31 Correct 18 ms 113016 KB Output is correct
32 Correct 18 ms 113016 KB Output is correct
33 Correct 304 ms 118264 KB Output is correct
34 Correct 376 ms 130780 KB Output is correct
35 Correct 351 ms 134424 KB Output is correct
36 Correct 359 ms 142312 KB Output is correct
37 Correct 268 ms 145084 KB Output is correct
38 Correct 250 ms 149144 KB Output is correct
39 Correct 295 ms 159940 KB Output is correct
40 Correct 295 ms 170864 KB Output is correct
41 Correct 219 ms 172996 KB Output is correct
42 Correct 256 ms 175884 KB Output is correct
43 Correct 218 ms 177868 KB Output is correct
44 Correct 269 ms 183908 KB Output is correct
45 Correct 219 ms 185948 KB Output is correct
46 Correct 216 ms 187992 KB Output is correct
47 Correct 270 ms 194464 KB Output is correct
48 Correct 275 ms 200656 KB Output is correct
49 Correct 327 ms 206720 KB Output is correct
50 Correct 332 ms 211904 KB Output is correct
51 Correct 333 ms 223756 KB Output is correct
52 Correct 343 ms 235104 KB Output is correct
53 Correct 308 ms 238476 KB Output is correct
54 Correct 314 ms 242320 KB Output is correct
55 Correct 259 ms 244644 KB Output is correct
56 Correct 324 ms 252112 KB Output is correct
57 Correct 258 ms 255052 KB Output is correct
58 Correct 259 ms 258376 KB Output is correct
59 Correct 277 ms 263672 KB Output is correct