Submission #209475

# Submission time Handle Problem Language Result Execution time Memory
209475 2020-03-14T10:16:34 Z my99n Horses (IOI15_horses) C++14
17 / 100
175 ms 31596 KB
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;

const long long mod = 1e9+7;
int n;
long long seg[2000100], x[500100], y[500100], lazy[2000100];

void build (int now = 1, int l = 0, int r = n-1) {
	lazy[now] = 1;
	if (l == r) return void(seg[now] = (x[l]*y[l])%mod);
	int mid = (l+r)/2;
	build(now*2, l, mid); build(now*2+1, mid+1, r);
	seg[now] = max(seg[now*2], seg[now*2+1]);
}

void push (int now) {
	if (lazy[now] == 1) return;
	lazy[now*2] *= lazy[now];
	lazy[now*2] %= mod;
	lazy[now*2+1] *= lazy[now];
	lazy[now*2+1] %= mod;
	seg[now] *= lazy[now];
	seg[now] %= mod;
	lazy[now] = 1;
}

long long query (int now = 1) {
	push(now);
	return seg[now];
}

void update (int a, int b, long long val, int now = 1, int l = 0, int r = n-1) {
	push(now);
	if (r < a or b < l) return;
	if (a <= l and r <= b) {
		lazy[now] *= val;
		lazy[now] %= mod;
		push(now);
		return;
	}
	int mid = (l+r)/2;
	update(a, b, val, now*2, l, mid); update(a, b, val, now*2+1, mid+1, r);
	seg[now] = max(seg[now*2], seg[now*2+1]);
}

long long inverse (long long a, long long n = mod-2) {
	if (n == 1) return a;
	long long r = inverse(a, n/2);
	r *= r;
	r %= mod;
	if (n&1) return (r*a) % mod;
	return r;
}

int init(int N, int X[], int Y[]) {
	n = N;
	x[0] = X[0];							
	for (int i = 1; i < n; i++) {
		x[i] = X[i]*x[i-1];
		x[i] %= mod;
	}
	for (int i = 0; i < n; i++) y[i] = Y[i];
	build(); // for (int i = 0; i < n; i++) cerr << x[i]*y[i] << endl;
	for (int i = 0; i < n; i++) x[i] = X[i];
	return (int)query();
}

int updateX(int pos, int val) {
	update(pos, n-1, inverse(x[pos]));
	x[pos] = val;
	update(pos, n-1, x[pos]);
	return query();
}

int updateY(int pos, int val) {
	update(pos, pos, inverse(y[pos]));
	assert(((inverse(y[pos]) * y[pos]) % mod) == 1);
	y[pos] = val;
	update(pos, pos, y[pos]);
	return query();
}

Compilation message

horses.cpp: In function 'long long int inverse(long long int, long long int)':
horses.cpp:47:52: warning: declaration of 'n' shadows a global declaration [-Wshadow]
 long long inverse (long long a, long long n = mod-2) {
                                                    ^
horses.cpp:6:5: note: shadowed declaration is here
 int n;
     ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:73:14: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return query();
         ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:81:14: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return query();
         ~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 0 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 408 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 6 ms 372 KB Output is correct
13 Correct 5 ms 368 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 424 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 364 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 424 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Incorrect 5 ms 376 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 175 ms 31596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 368 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 424 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Incorrect 5 ms 376 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 6 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Incorrect 5 ms 376 KB Output isn't correct
22 Halted 0 ms 0 KB -