Submission #793563

# Submission time Handle Problem Language Result Execution time Memory
793563 2023-07-26T02:35:49 Z duyanhloveav Growing Trees (BOI11_grow) C++17
30 / 100
1000 ms 3336 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#define int long long

const int N = 9 + 1e5;
const int oo = 7 + 1e9;

int a[N];

void SaKaTa() {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort (a + 1, a + 1 + n);
    while (m--) {
        char c;
        int l, r;
        cin >> c >> l >> r;
        if (c == 'F') {
            int pos = lower_bound(a + 1, a + 1 + n, r) - a;
            if (pos != (n + 1)) {
                for (int i = pos; i <= n; i++) {
                    a[i]++;
                    l--;
                    if (l == 0) break;
                }
                sort (a + 1, a + 1 + n);
            }
        } else {
            int pos = lower_bound(a + 1, a + 1 + n, l) - a;
            if (pos != (n + 1) && a[pos] <= r) {
                int pos_two = upper_bound(a + 1, a + 1 + n, r) - a - 1;
                cout << pos_two - pos + 1 << '\n';
            } else cout << 0 << '\n';
        }
    }
}

int32_t main() {
#define TASKNAME "TREE"
    cin.tie(0)->sync_with_stdio(0);
    if ( fopen( TASKNAME".inp", "r" ) ) {
        freopen (TASKNAME".inp", "r", stdin);
        freopen (TASKNAME".out", "w", stdout);
    }
    int testcase = 1;
//    scanf("%d", &testcase);
    while (testcase--)
        SaKaTa();
    return 0;
}

Compilation message

grow.cpp: In function 'int32_t main()':
grow.cpp:47:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         freopen (TASKNAME".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
grow.cpp:48:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         freopen (TASKNAME".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 1504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 234 ms 1428 KB Output is correct
6 Correct 237 ms 1660 KB Output is correct
7 Correct 119 ms 424 KB Output is correct
8 Correct 37 ms 1040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 359 ms 1644 KB Output is correct
2 Correct 437 ms 1872 KB Output is correct
3 Correct 22 ms 408 KB Output is correct
4 Correct 50 ms 1276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 310 ms 1836 KB Output is correct
2 Correct 444 ms 1612 KB Output is correct
3 Correct 420 ms 480 KB Output is correct
4 Correct 329 ms 1740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 1236 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 1396 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 1312 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1080 ms 1752 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 1472 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1072 ms 3336 KB Time limit exceeded
2 Halted 0 ms 0 KB -