Submission #937800

# Submission time Handle Problem Language Result Execution time Memory
937800 2024-03-04T13:23:29 Z nguyentunglam Fish 2 (JOI22_fish2) C++17
0 / 100
4000 ms 3572 KB
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define endl "\n"
#define int long long
using namespace std;

const int N = 1e5 + 10;

int a[N];

int32_t main() {
  #define task ""

  cin.tie(0) -> sync_with_stdio(0);

  if (fopen("task.inp", "r")) {
    freopen("task.inp", "r", stdin);
    freopen("task.out", "w", stdout);
  }

  if (fopen(task".inp", "r")) {
    freopen (task".inp", "r", stdin);
    freopen (task".out", "w", stdout);
  }

  int n; cin >> n;

  for(int i = 1; i <= n; i++) cin >> a[i];

  int q; cin >> q;

  a[0] = a[n + 1] = 1e18;

  while (q--) {
    int t, x, y; cin >> t >> x >> y;
    if (t == 1) a[x] = y;
    else {
      int ans = 0;
      vector<pair<int, int> > line;
      for(int l = 1; l <= n; l++) {
        long long sum = 0;
        for(int r = l; r <= n - (l == 1); r++) {
          sum += a[r];
          if (sum < a[l - 1] && sum < a[r + 1]) line.emplace_back(l, r);
        }
      }
      int _x = x, _y = y;
      long long sum = 0;
      for(int i = y; i >= x; i--) {
        if (a[i] > sum) _y = i;
        sum += a[i];
      }
      sum = 0;
      for(int i = x; i <= y; i++) {
        if (a[i] > sum) _x = i;
        sum += a[i];
      }
      x = _x;
      y = _y;
      assert(line.size() <= n);
      for(int i = x; i <= y; i++) {
        bool ok = 1;
        for(auto &[l, r] : line) if (l <= i && i <= r) {
          if (l >= x || r <= y) ok = 0;
        }
        ans += ok;
      }
      cout << ans << endl;
    }
  }
}



Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from fish2.cpp:1:
fish2.cpp: In function 'int32_t main()':
fish2.cpp:60:26: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   60 |       assert(line.size() <= n);
      |              ~~~~~~~~~~~~^~~~
fish2.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     freopen("task.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fish2.cpp:18:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     freopen("task.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
fish2.cpp:22:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     freopen (task".inp", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fish2.cpp:23:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     freopen (task".out", "w", stdout);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 Incorrect 13 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 4061 ms 3572 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 Incorrect 13 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 4061 ms 3572 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 4061 ms 3572 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 Incorrect 13 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -