Submission #695093

# Submission time Handle Problem Language Result Execution time Memory
695093 2023-02-04T17:34:47 Z Nhoksocqt1 Relativnost (COCI15_relativnost) C++17
0 / 140
3448 ms 41288 KB
#include<bits/stdc++.h>
using namespace std;

#define inf 0x3f3f3f3f
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;

template<class X, class Y>
	inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
	inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

int readInt() {
	bool minus = false;
	int result = 0;
	char ch;
	ch = getchar();
	while(true) {
		if(ch == '-') break;
		if(ch >= '0' && ch <= '9') break;
		ch = getchar();
	}

	if(ch == '-') minus = true; else result = ch - '0';
	while(true) {
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		result = result * 10 + (ch - '0');
	}

	if(minus)
		return -result;
	else
		return result;
}

const int MAXN = 100005;
const int modl = 10007;

struct Node {
    int f[21], a, b;

    Node() {
        memset(f, 0, sizeof(f));
        a = b = 0;
    }

} seg[4 * MAXN];

int a[MAXN], b[MAXN], nArr, numQuery, C;

inline void add(int &a, const int &b) {
    if((a += b) >= modl)
        a -= modl;
}

void mergeNode(Node &res, const Node &a, const Node &b) {
    for (int i = 0; i <= C; ++i)
        res.f[i] = 0;

    for (int i = 0; i <= C; ++i) {
        for (int j = 0; j <= C; ++j) {
            add(res.f[min(i + j, C)], a.f[i] * b.f[j] % modl);
        }
    }
}

void build(int id, int l, int r) {
    if(l == r) {
        seg[id].f[0] = b[l], seg[id].f[1] = a[l];
        seg[id].a = a[l], seg[id].b = b[l];
        return;
    }

    int mid = (l + r) >> 1;
    build(id << 1, l, mid);
    build(id << 1 | 1, mid + 1, r);
    mergeNode(seg[id], seg[id << 1], seg[id << 1 | 1]);
}

void update(int pos, int a, int b) {
    int id(1), l(1), r(nArr);
    while(l != r) {
        int mid = (l + r) >> 1;
        if(pos <= mid) {
            id <<= 1;
            r = mid;
        } else {
            id = id << 1 | 1;
            l = mid + 1;
        }
    }

    seg[id].f[0] = b, seg[id].f[1] = a;
    seg[id].a = a, seg[id].b = b;
    while(id > 1) {
        id >>= 1;
        mergeNode(seg[id], seg[id << 1], seg[id << 1 | 1]);
    }
}

void process() {
    cin >> nArr >> C;
    for (int i = 1; i <= nArr; ++i) {
        cin >> a[i];
    }

    for (int i = 1; i <= nArr; ++i) {
        cin >> b[i];
    }

    build(1, 1, nArr);

    cin >> numQuery;
    for (int t = 0; t < numQuery; ++t) {
        int pos, a, b;
        cin >> pos >> a >> b;
        update(pos, a, b);
        cout << seg[1].f[C] << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//    freopen("relativnost.inp", "r", stdin);
//    freopen("relativnost.out", "w", stdout);

    process();
    return 0;
}

Compilation message

relativnost.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    6 | #pragma GCC optimization ("O3")
      | 
relativnost.cpp:7: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    7 | #pragma GCC optimization ("unroll-loops")
      |
# Verdict Execution time Memory Grader output
1 Runtime error 28 ms 36308 KB Memory limit exceeded
2 Runtime error 36 ms 36312 KB Memory limit exceeded
3 Runtime error 44 ms 36308 KB Memory limit exceeded
4 Runtime error 434 ms 39764 KB Memory limit exceeded
5 Runtime error 1522 ms 41148 KB Memory limit exceeded
6 Runtime error 2224 ms 40896 KB Memory limit exceeded
7 Runtime error 1004 ms 40012 KB Memory limit exceeded
8 Runtime error 528 ms 40532 KB Memory limit exceeded
9 Runtime error 952 ms 41288 KB Memory limit exceeded
10 Runtime error 3448 ms 41188 KB Memory limit exceeded