Submission #1279394

#TimeUsernameProblemLanguageResultExecution timeMemory
1279394swishy123Horses (IOI15_horses)C++20
Compilation error
0 ms0 KiB
#include <stdio.h>
#include <stdlib.h>
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const int def = 5e5+1;
const ll mod = 1e9+7;

ll powmod(ll a, ll b){
    if (b == 0)
        return 1;
    if (b % 2 == 0){
        ll val = powmod(a, b / 2);
        return (val * val) % mod;
    }
    else
        return (a * powmod(a, b - 1)) % mod;
}
ll inv(ll x){
    return powmod(x, mod - 2);
}

ll bit[def];
void apply(int u, ll val){
    for (int i = u; i < def; i += i & -i)
        (bit[i] *= val) %= mod; 
}
ll query(int u){
    ll res = 1;
    for (int i = u; i > 0; i -= i & -i)
        (res *= bit[i]) %= mod;
    return res;
}

ll x[def], y[def];
int n;

int get(){
    int l = n - 1;
    __int128_t crr = x[l];

    __int128_t bound = (__int128_t)1e18;
    while (l - 1 >= 0 && (crr * (__int128_t)x[l - 1]) <= bound){
        crr *= x[l - 1];
        l--;
    }
    
    ll prefix = query(l);
    __int128_t best = 1;
    crr = 1;
    for (int i = l; i < n; i++){
        crr *= x[i];
        __int128_t val = crr * y[i];
        
        best = max(best, val);
    }
    best %= mod;
    ll res = (prefix * best) % mod;
    return res;
}

int init(int N, int X[], int Y[]){
    n = N;
    for (int i = 0; i < def; i++)
        bit[i] = 1;
    for (int i = 0; i < n; i++){
        x[i] = X[i];
        apply(i + 1, x[i]);
        y[i] = Y[i];
    }
    return get();
}

int updateX(int pos, int val){	
    apply(pos + 1, ((ll)inv(x[pos]) * (ll)val) % mod);
    x[pos] = val;
	return get();
}

int updateY(int pos, int val){
    y[pos] = val;
	return get();
}


static char _buffer[1024];
static int _currentChar = 0;
static int _charsNumber = 0;
static FILE *_inputFile, *_outputFile;

static inline int _read() {
    if (_charsNumber < 0) {
        exit(1);
    }
    if (!_charsNumber || _currentChar == _charsNumber) {
        _charsNumber = (int)fread(_buffer, sizeof(_buffer[0]), sizeof(_buffer), _inputFile);
        _currentChar = 0;
    }
    if (_charsNumber <= 0) {
        return -1;
    }
    return _buffer[_currentChar++];
}

static inline int _readInt() {
    int c, x, s;
    c = _read();
    while (c <= 32) c = _read();
    x = 0;
    s = 1;
    if (c == '-') {
        s = -1;
        c = _read();
    }
    while (c > 32) {
        x *= 10;
        x += c - '0';
        c = _read();
    }
    if (s < 0) x = -x;
    return x;
}


int main() {
	_inputFile = fopen("horses.in", "rb");
	_outputFile = fopen("horses.out", "w");
	
	int N; N = _readInt();

	int *X = (int*)malloc(sizeof(int)*(unsigned int)N);
	int *Y = (int*)malloc(sizeof(int)*(unsigned int)N);

	for (int i = 0; i < N; i++) {
		X[i] = _readInt();
	}

	for (int i = 0; i < N; i++) {
		Y[i] = _readInt();
	}	

	fprintf(_outputFile,"%d\n",init(N,X,Y));

	int M; M = _readInt();

	for (int i = 0; i < M; i++) {
		int type; type = _readInt();
		int pos; pos = _readInt();
		int val; val = _readInt(); 

		if (type == 1) {
			fprintf(_outputFile,"%d\n",updateX(pos,val));
		} else if (type == 2) {
			fprintf(_outputFile,"%d\n",updateY(pos,val));
		}
	}

	return 0;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccEHAgfx.o: in function `main':
grader.c:(.text.startup+0x0): multiple definition of `main'; /tmp/ccwEIikA.o:horses.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status