QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#118132#6626. Real Mountainshos_lyric#0 0ms4104kbC++143.5kb2023-07-03 09:05:312024-05-31 18:48:26

Judging History

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

  • [2024-05-31 18:48:26]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:4104kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-03 09:05:31]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }


vector<int> uf;
int root(int u) {
  return (uf[u] < 0) ? u : (uf[u] = root(uf[u]));
}
bool connect(int u, int v) {
  u = root(u);
  v = root(v);
  if (u == v) return false;
  if (uf[u] > uf[v]) swap(u, v);
  uf[u] += uf[v];
  uf[v] = u;
  return true;
}


constexpr int MO = 1'000'003;
constexpr Int INF = 1001001001001001001LL;

int N;
vector<Int> A;

int main() {
  for (; ~scanf("%d", &N); ) {
    A.assign(N + 2, INF);
    for (int i = 1; i <= N; ++i) {
      scanf("%lld", &A[i]);
    }
    
    vector<int> prv(N + 2, 0), nxt(N + 2, N + 1);
    for (int i = 1; i <= N; ++i) {
      int &j = prv[i] = i - 1;
      for (; A[j] <= A[i]; j = prv[j]) {}
    }
    for (int i = N; i >= 1; --i) {
      int &j = nxt[i] = i + 1;
      for (; A[j] < A[i]; j = nxt[j]) {}
    }
// cerr<<"prv = "<<prv<<endl;
// cerr<<"nxt = "<<nxt<<endl;
    
    vector<Int> costs(N + 2, 0);
    for (int i = 1; i <= N; ++i) if (1 <= prv[i] && nxt[i] <= N) {
      const Int tar = min(A[prv[i]], A[nxt[i]]);
      costs[i] += tar * (tar - 1) / 2 - A[i] * (A[i] - 1) / 2;
      {
        vector<Int> bs;
        for (int j = 1; j < i; ++j) if (A[j] > A[i]) {
          bs.push_back(A[j]);
        }
        sort(bs.begin(), bs.end());
        Int a = A[i];
        for (const Int b : bs) {
          const Int aa = min(b, tar);
          costs[i] += (aa - a) * b;
          a = aa;
        }
      }
      {
        vector<Int> bs;
        for (int j = i + 1; j <= N; ++j) if (A[j] > A[i]) {
          bs.push_back(A[j]);
        }
        sort(bs.begin(), bs.end());
        Int a = A[i];
        for (const Int b : bs) {
          const Int aa = min(b, tar);
          costs[i] += (aa - a) * b;
          a = aa;
        }
      }
    }
// cerr<<"costs = "<<costs<<endl;
    
    vector<pair<Int, int>> ps;
    for (int i = 1; i <= N; ++i) if (1 <= prv[i] && nxt[i] <= N) {
      ps.emplace_back(A[i], i);
    }
    sort(ps.begin(), ps.end());
// cerr<<"ps = "<<ps<<endl;
    
    Int ans = 0;
    uf.assign(N, -1);
    for (const auto &p : ps) {
      const int i = p.second;
      ans += (costs[i] % MO) * (-uf[root(i)]);
      ans %= MO;
      connect(i, (A[prv[i]] <= A[nxt[i]]) ? prv[i] : nxt[i]);
    }
    printf("%lld\n", ans);
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 0ms
memory: 4104kb

input:

3
29 9 9

output:

0

result:

ok 1 number(s): "0"

Test #2:

score: 0
Accepted
time: 0ms
memory: 4052kb

input:

3
62 20 71

output:

7287

result:

ok 1 number(s): "7287"

Test #3:

score: -3
Wrong Answer
time: 0ms
memory: 3768kb

input:

10
72 33 22 22 13 49 53 57 72 85

output:

44479

result:

wrong answer 1st numbers differ - expected: '40403', found: '44479'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #3:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%