답안 #955385

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
955385 2024-03-30T10:19:30 Z hariaakas646 말 (IOI15_horses) C++17
37 / 100
529 ms 73884 KB
#include "horses.h"
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;


template <class T>
struct SegTree
{
    int size = 1, n;
    vector<T> segtree;
    vector<T> vec;

    T def; // Assign a value

    void init(int l, T defv)
    {
        n = l;
        def = defv;

        while (size < n)
            size *= 2;

        segtree.assign(2 * size, def);
        vec.assign(size, def);
    }

    T operation(T x, T y)
    {
        return max(x, y); // Any required operation
    }

    void recalculate(int x)
    {
        segtree[x] = operation(segtree[2 * x + 1], segtree[2 * x + 2]);
    }

    void build(int x, int l, int r)
    {
        if (l == r)
        {
            segtree[x] = vec[l];
            return;
        }
        int mid = (l + r) / 2;
        build(2 * x + 1, l, mid);
        build(2 * x + 2, mid + 1, r);
        recalculate(x);
    }

    void build()
    {
        build(0, 0, size - 1);
    }

    void set(int id, T val)
    {
        vec[id] = val;
    }

    void update(int x, int l, int r, int id, T val)
    {
        if (l == r)
        {
            segtree[x] = val;
            return;
        }
        int mid = (l + r) / 2;
        if (id <= mid)
        {
            update(2 * x + 1, l, mid, id, val);
        }
        else
        {
            update(2 * x + 2, mid + 1, r, id, val);
        }
        recalculate(x);
    }

    void update(int id, T val)
    {
        update(0, 0, size - 1, id, val);
    }

    T query(int x, int l, int r, int lx, int rx)
    {
        if (lx > r || rx < l)
        {
            return def;
        }
        if (lx <= l && r <= rx)
        {
            return segtree[x];
        }
        int mid = (l + r) / 2;
        T v1 = query(2 * x + 1, l, mid, lx, rx);
        T v2 = query(2 * x + 2, mid + 1, r, lx, rx);
        return operation(v1, v2);
    }

    T query(int lx, int rx)
    {
        return query(0, 0, size - 1, lx, rx);
    }
};

const lli mod = 1e9 + 7;

template <class T>
struct SegTreeMul
{
    int size = 1, n;
    vector<T> segtree;
    vector<T> vec;

    T def; // Assign a value

    void init(int l, T defv)
    {
        n = l;
        def = defv;

        while (size < n)
            size *= 2;

        segtree.assign(2 * size, def);
        vec.assign(size, def);
    }

    T operation(T x, T y)
    {
        return (x*y)%mod; // Any required operation
    }

    void recalculate(int x)
    {
        segtree[x] = operation(segtree[2 * x + 1], segtree[2 * x + 2]);
    }

    void build(int x, int l, int r)
    {
        if (l == r)
        {
            segtree[x] = vec[l];
            return;
        }
        int mid = (l + r) / 2;
        build(2 * x + 1, l, mid);
        build(2 * x + 2, mid + 1, r);
        recalculate(x);
    }

    void build()
    {
        build(0, 0, size - 1);
    }

    void set(int id, T val)
    {
        vec[id] = val;
    }

    void update(int x, int l, int r, int id, T val)
    {
        if (l == r)
        {
            segtree[x] = val;
            return;
        }
        int mid = (l + r) / 2;
        if (id <= mid)
        {
            update(2 * x + 1, l, mid, id, val);
        }
        else
        {
            update(2 * x + 2, mid + 1, r, id, val);
        }
        recalculate(x);
    }

    void update(int id, T val)
    {
        update(0, 0, size - 1, id, val);
    }

    T query(int x, int l, int r, int lx, int rx)
    {
        if (lx > r || rx < l)
        {
            return def;
        }
        if (lx <= l && r <= rx)
        {
            return segtree[x];
        }
        int mid = (l + r) / 2;
        T v1 = query(2 * x + 1, l, mid, lx, rx);
        T v2 = query(2 * x + 2, mid + 1, r, lx, rx);
        return operation(v1, v2);
    }

    T query(int lx, int rx)
    {
        return query(0, 0, size - 1, lx, rx);
    }
};

SegTree<lli> segtree;
SegTreeMul<lli> segmul;
seti act;
vll v1, v2;
int n;

int init(int N, int X[], int Y[]) {
	n = N;
	segtree.init(n, 0LL);
	segmul.init(n, 1);
	v1 = v2 = vll(n);

	frange(i, n) {
		if(X[i] != 1) act.insert(i);
		v1[i] = X[i];
		v2[i] = Y[i];
		segtree.set(i, v2[i]);
		segmul.set(i, v1[i]);
	}
	act.insert(0);
	segtree.build();
	segmul.build();

	auto it = act.end();
	frange(i, 30) {
		it--;
		if(it == act.begin()) break;
	}
	int ma = *it;
	lli v = segtree.query(ma, n-1);
	it++;
	lli curr = 1;
	while(it != act.end()) {
		int id = *it;
		curr *= v1[id];
		lli val = segtree.query(id, n-1);
		if(curr >= v || curr * val >= v) {
			ma = id;
			v = val;
			curr = 1;
		}
		it++;
	}

	lli out = segmul.query(0, ma) * segtree.query(ma, n-1) % mod;

	return out;
}

int updateX(int pos, int val) {	
	segmul.update(pos, val);
	if(v1[pos] != 1 && val == 1) act.erase(pos);
	if(val != 1) act.insert(pos);
	v1[pos] = val;

	auto it = act.end();
	frange(i, 30) {
		it--;
		if(it == act.begin()) break;
	}
	int ma = *it;
	lli v = segtree.query(ma, n-1);
	it++;
	lli curr = 1;
	while(it != act.end()) {
		int id = *it;
		curr *= v1[id];
		lli val = segtree.query(id, n-1);
		if(curr >= v || curr * val >= v) {
			ma = id;
			v = val;
			curr = 1;
		}
		it++;
	}

	lli out = segmul.query(0, ma) * segtree.query(ma, n-1) % mod;

	return out;
}

int updateY(int pos, int val) {
	segtree.update(pos, val);
	v2[pos] = val;

	auto it = act.end();
	frange(i, 30) {
		it--;
		if(it == act.begin()) break;
	}
	int ma = *it;
	lli v = segtree.query(ma, n-1);
	it++;
	lli curr = 1;
	while(it != act.end()) {
		int id = *it;
		curr *= v1[id];
		lli val = segtree.query(id, n-1);
		if(curr >= v || curr * val >= v) {
			ma = id;
			v = val;
			curr = 1;
		}
		it++;
	}

	lli out = segmul.query(0, ma) * segtree.query(ma, n-1) % mod;

	return out;
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:277:9: warning: conversion from 'lli' {aka 'long long int'} to 'int' may change value [-Wconversion]
  277 |  return out;
      |         ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:298:7: warning: declaration of 'lli val' shadows a parameter [-Wshadow]
  298 |   lli val = segtree.query(id, n-1);
      |       ^~~
horses.cpp:280:26: note: shadowed declaration is here
  280 | int updateX(int pos, int val) {
      |                      ~~~~^~~
horses.cpp:309:9: warning: conversion from 'lli' {aka 'long long int'} to 'int' may change value [-Wconversion]
  309 |  return out;
      |         ^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:328:7: warning: declaration of 'lli val' shadows a parameter [-Wshadow]
  328 |   lli val = segtree.query(id, n-1);
      |       ^~~
horses.cpp:312:26: note: shadowed declaration is here
  312 | int updateY(int pos, int val) {
      |                      ~~~~^~~
horses.cpp:339:9: warning: conversion from 'lli' {aka 'long long int'} to 'int' may change value [-Wconversion]
  339 |  return out;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 440 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 436 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 360 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 436 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 600 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 3 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 3 ms 604 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 3 ms 348 KB Output is correct
29 Runtime error 1 ms 600 KB Execution killed with signal 11
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 374 ms 65208 KB Output is correct
2 Correct 475 ms 73884 KB Output is correct
3 Correct 444 ms 65072 KB Output is correct
4 Correct 529 ms 68800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 440 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 3 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 3 ms 348 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 3 ms 348 KB Output is correct
29 Runtime error 1 ms 604 KB Execution killed with signal 11
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 544 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 3 ms 548 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 3 ms 480 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 3 ms 348 KB Output is correct
29 Runtime error 1 ms 604 KB Execution killed with signal 11
30 Halted 0 ms 0 KB -