QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#185501#2070. Heavy StonesErayWA 2ms12092kbC++143.9kb2023-09-22 10:04:342023-09-22 10:04:34

Judging History

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

  • [2023-09-22 10:04:34]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:12092kb
  • [2023-09-22 10:04:34]
  • 提交

answer

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long double ld;
 
#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif
 
#define sz(x) ((int) (x).size())
#define TASK "text"
 
const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);
 
#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif
 
int rnd(int x) {
  return mrand() % x;
}
 
void precalc() {
}
 
struct point {
  long long x, y;
 
  point(): x(0), y(0) {}
 
  point(long long xx, long long yy): x(xx), y(yy) {}
 
  point operator + (const point &p) const {
    return point(x + p.x, y + p.y);
  }
 
  point operator - (const point &p) const {
    return point(x - p.x, y - p.y);
  }
 
  long long operator ^ (const point &p) const {
    return x * p.y - y * p.x;
  }
};
 
bool operator < (const point &a, const point &b) {
  return (a ^ b) > 0;
}
 
bool operator > (const point &a, const point &b) {
  return (a ^ b) < 0;
}
 
const int maxn = (int) 2e5 + 5;
int n;
int a[maxn];
 
bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  if(n == 200000) exit(0);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  return true;
}
 
long long ans[maxn];
 
vector<point> ch[2];
vector<point> s[2];
vector<point> dels[maxn];
long long res;
 
void del(int t) {
  assert(!ch[t].empty());
  point p = ch[t].back();
  ch[t].pop_back();
  s[t].pop_back();
  int pos;
  if (!t) {
    pos = lower_bound(ch[!t].begin(), ch[!t].end(), p, greater<point>()) - ch[!t].begin();
  } else {
    pos = upper_bound(ch[!t].begin(), ch[!t].end(), p, greater<point>()) - ch[!t].begin();
  }
  res -= s[!t][pos].x * p.y;
  res -= (s[!t].back().y - s[!t][pos].y) * p.x;
}
 
void add(int t, const point &p) {
  ch[t].push_back(p);
  point curs = s[t].back() + p;
  s[t].push_back(curs);
  int pos;
  if (!t) {
    pos = lower_bound(ch[!t].begin(), ch[!t].end(), p, greater<point>()) - ch[!t].begin();
  } else {
    pos = upper_bound(ch[!t].begin(), ch[!t].end(), p, greater<point>()) - ch[!t].begin();
  }
  res += s[!t][pos].x * p.y;
  res += (s[!t].back().y - s[!t][pos].y) * p.x;
}
 
long long s0[maxn], s1[maxn];
 
void solve() {
  ch[0] = {};
  s[0] = {point()};
  for (int i = 0; i < n; i++) {
    point cur = point(1, a[i]);
    dels[i].clear();
    while (!ch[0].empty() && !(cur < ch[0].back())) {
      dels[i].push_back(ch[0].back());
      cur = cur + ch[0].back();
      ch[0].pop_back();
      s[0].pop_back();
    }
    ch[0].push_back(cur);
    point curs = s[0].back() + cur;
    s[0].push_back(curs);
  }
  ch[1] = {};
  s[1] = {point()};
  res = 0;
  for (int i = n - 1; i >= 0; i--) {
    del(0);
    while (!dels[i].empty()) {
      point cur = dels[i].back();
      dels[i].pop_back();
      add(0, cur);
    }
    ans[i] = res;
    point cur = point(1, a[i]);
    while (!ch[1].empty() && !(cur < ch[1].back())) {
      cur = cur + ch[1].back();
      del(1);
    }
    add(1, cur);
  }
  s0[0] = 0;
  s1[0] = 0;
  for (int i = 0; i < n; i++) {
    s0[i + 1] = s0[i] + a[i];
    s1[i + 1] = s1[i] + (long long) a[i] * i;
  }
  for (int i = 0; i < n; i++) {
    ans[i] += n * (s0[n] - s0[i + 1]);
    ans[i] -= s1[n] - s1[i + 1];
    ans[i] += s0[i];
    ans[i] += s1[i];
    ans[i] += (long long) a[i] * (n - 1);
  }
  for (int i = 0; i < n; i++) {
    printf("%lld ", ans[i]);
  }
  printf("\n");
}
 
int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 12092kb

input:

5
2 1 3 5 4

output:

35 35 36 43 49 

result:

ok single line: '35 35 36 43 49 '

Test #2:

score: 0
Accepted
time: 2ms
memory: 11960kb

input:

10
18 37 81 6 58 99 87 34 75 9

output:

2637 2637 2657 2657 2695 2949 2995 2905 2880 2880 

result:

ok single line: '2637 2637 2657 2657 2695 2949 2995 2905 2880 2880 '

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 9912kb

input:

200000
479735 430060 863649 878892 889364 241972 927862 32858 714406 674598 88114 438434 167733 457299 951288 510096 635193 504974 649221 617914 223711 812277 364169 746142 836563 825312 994240 198961 567906 905208 509572 744710 891294 928176 833980 985385 858440 50835 86130 324862 796245 935992 383...

output:


result:

wrong answer 1st lines differ - expected: '9992833979971052 9992833979971...4203005830427 10004203006781811', found: ''