QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#392508#7944. Max Minus Minucup-team3215#TL 1ms3816kbC++201.0kb2024-04-17 16:36:342024-04-17 16:36:35

Judging History

你现在查看的是最新测评结果

  • [2024-04-17 16:36:35]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3816kb
  • [2024-04-17 16:36:34]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  for (int tc = (cin >> tc, tc); tc--; ) {
    int n; cin >> n;
    vector<int> v(n); for (auto& x: v) cin >> x;
    multiset<int> si, so;
    for (int i = 0; i < n; ++i) so.insert(v[i]);
    int ans = 1e9;
    auto relax = [&] {
      int cans = 0;
      if (so.size()) cans = max(cans, *so.rbegin() - *so.begin());
      if (si.size()) cans = max(cans, *si.rbegin() - *si.begin());
      ans = min(ans, cans);
    };
    for (int i = 0, r = 0; r < n; ++i) {
      if (si.size()) {
        si.erase(si.find(v[i - 1]));
        so.insert(v[i - 1]);
      }
      relax();
      while (r < n) {
        so.erase(so.find(v[r]));
        si.insert(v[r]);
        relax();
        if (si.size() && (so.empty() || *so.rbegin() - *so.begin() < *si.rbegin() - *si.begin())) {
          si.erase(si.find(v[r]));
          so.insert(v[r]);
          break;
        } else ++r;
      }
    }
    cout << ans << '\n';
  }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3816kb

input:

4
3
42 42 42
4
1 2 2 1
5
1 100 1 100 1
6
1 2 3 4 5 6

output:

0
0
99
2

result:

ok 4 number(s): "0 0 99 2"

Test #2:

score: -100
Time Limit Exceeded

input:

19530
6
2 3 3 3 4 3
6
2 4 4 2 5 5
6
2 5 2 5 1 3
6
4 4 1 2 4 1
5
5 4 5 3 3
5
2 2 1 5 1
6
3 1 2 4 2 3
5
5 5 4 4 5
6
5 3 3 1 4 2
6
3 3 2 4 2 4
6
1 2 4 5 2 5
5
3 4 5 5 3
6
4 3 3 3 4 3
6
1 5 1 2 3 1
5
5 5 2 1 4
6
1 2 5 3 5 2
6
4 5 2 4 5 2
5
2 4 2 4 1
4
2 3 3 3
6
1 2 2 1 4 5
6
3 2 1 3 3 2
6
2 1 1 2 5 3
6
...

output:


result: