Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <vector>
- using namespace std;
- const int log = 25;
- vector<int>a;
- long long opt[3];
- vector<vector<long long>>st;
- int n;
- vector<long long>precalc;
- void precalcy() {
- precalc[0] = 0;
- precalc[1] = 1;
- for (int i = 2; i <= n; i++) {
- precalc[i] = precalc[i - 1];
- if ((1 << (precalc[i] + 1)) <= i) {
- precalc[i]++;
- }
- }
- }
- void prep() {
- for (int i = 0; i < n; i++) {
- st[i][0] = a[i];
- }
- for (int j = 1; (1 << j) <= n; j++) {
- for (int i = 0; i + (1 << j) <= n; i++) { /// у тебя этот цикл шел до < n, ну зачем ты так с ним ??? :(
- st[i][j] = min(st[i][j - 1], st[i + (1 << (j-1))][j-1]);
- }
- }
- }
- long long func (int l, int r) {
- int j = precalc[r - l + 1];
- return min(st[l][j], st[r - (1 << j) + 1][j]);
- }
- int main() {
- /// убираю файлики, на всякий случай :)
- /// freopen("crypto.in", "r", stdin);
- /// freopen("crypto.out", "w", stdout);
- /// ios::sync_with_stdio(false); - это неправильно, ниже напишу правильно
- ios_base::sync_with_stdio(false);
- cin.tie(); /// - cin.tie() наоборот увеличивает время работы :(
- int m;
- cin >> n >> m;
- a.resize(n);
- cin >> a[0];
- for (int i = 1; i < n; i++) {
- a[i] = (23 * a[i - 1] + 21563) % 16714589;
- }
- precalc.resize(n + 1);
- precalcy();
- st.resize(n + 2); /// возьмём с запасом, на всякий случай.
- for (int i = 0; i <= n; i++) {
- st[i].resize(log);
- }
- prep();
- cin >> opt[0] >> opt[1];
- /// opt[2] = func(opt[0] - 1, opt[1] - 1); /// это конечно хорошо,
- /// но где гарантии, что opt[0] < opt[1] ???
- opt[2] = func(min(opt[0], opt[1]) - 1, max(opt[0], opt[1]) - 1);
- for (int i = 1; i < m; i++) {
- opt[0] = (( 17 * opt[0] + 751 + opt[2] + 2 * (i - 1)) % n) + 1;
- opt[1] = (( 13 * opt[1] + 593 + opt[2] + 5 * (i - 1)) % n) + 1;
- /// opt[2] = func(opt[0] - 1, opt[1] - 1); опят же )
- opt[2] = func(min(opt[0], opt[1]) - 1, max(opt[0], opt[1]) - 1);
- }
- cout << opt[0] << " " << opt[1] << " " << opt[2];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement