QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#398406#3765. Make Rounddog *Very* HappySamponYW#TL 0ms0kbC++143.1kb2024-04-25 11:45:282024-04-25 11:45:29

Judging History

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

  • [2024-04-25 11:45:29]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-04-25 11:45:28]
  • 提交

answer

#include <bits/stdc++.h>
#define int ll
#define db double
#define il inline
#define re register
#define ll long long
#define ui unsigned
#define ull ui ll
#define i128 __int128
#define pii pair<int, int>
#define fi first
#define se second
#define eb emplace_back
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(), v.end()
#define mems(v, x) memset(v, x, sizeof(v))
#define memc(a, b) memcpy(a, b, sizeof(a))
#define FOR(i, L, R) for(re int i = (L); i <= (R); ++i)
#define ROF(i, R, L) for(re int i = (R); i >= (L); --i)
#define LS i << 1, l, mid
#define RS i << 1 | 1, mid + 1, r
#define popc(x) __builtin_popcount(x)
using namespace std;
#define N 1000005
#define P 1000000007
il int add(int x, int y) {return x + y < P ? x + y : x + y - P;}
il void addr(int &x, int y) {(x += y) >= P && (x -= P);}
il int qpow(int p, int n = P - 2) {
  int s = 1;
  while(n) {
    if(n & 1) s = 1ll * s * p % P;
    p = 1ll * p * p % P, n >>= 1;
  }
  return s;
}
int n, m;
namespace seg {
  int s[N * 4], t[N * 4];
  il void build(int i = 1, int l = 1, int r = n) {
    s[i] = t[i] = 0; if(l == r) return ;
    int mid = l + r >> 1; build(LS), build(RS);
  }
  il void pushup(int i) {s[i] = s[i << 1] + s[i << 1 | 1];}
  il void push(int i, int l, int r, int v) {s[i] += v * (r - l + 1), t[i] += v;}
  il void pushdown(int i, int l, int r) {int mid = l + r >> 1; push(LS, t[i]), push(RS, t[i]), t[i] = 0;}
  il void upd(int el, int er, int v, int i = 1, int l = 1, int r = n) {
    if(l >= el && r <= er) return push(i, l, r, v); int mid = l + r >> 1; pushdown(i, l, r);
    if(mid >= el) upd(el, er, v, LS); if(mid < er) upd(el, er, v, RS); pushup(i);
  }
  il int query(int x, int i = 1, int l = 1, int r = n) {
    if(r <= x) return s[i]; int mid = l + r >> 1; pushdown(i, l, r);
    int s = query(x, LS); if(mid < x) s += query(x, RS); return s;
  }
}
namespace bit {
  int s[N];
  il void clr() {FOR(i, 1, n) s[i] = 0;}
  il void upd(int x, int v) {while(x <= n) s[x] += v, x += x & -x;}
  il int query(int x) {int v = 0; while(x) v += s[x], x ^= x & -x; return v;}
}
struct node {int l, r, v;} ;
il void upd(node t, int k) {
/*
max - (j - i + 1) >= m
j <= max + i - 1 - m
*/
  auto [l, r, v] = t;
  // cerr << l << " " << r << " " << v << "\n";
  int L = v + l - 1 - m, R = v + r - 1 - m, A = r - l + 1;
  if(L <= 0) A -= 1 - L, L = 1; if(R <= 0) return ; R = min(R, n);
  // cerr << L << " " << R << " += " << A << " " << -k << "\n";
  bit::upd(1, A * k); if(L < R) seg::upd(L + 1, R, k);
  if(R < n) seg::upd(R + 1, R + 1, (A - (R - L)) * k);
}
il void WORK() {
  seg::build(), bit::clr();
  vector<node> s;
  FOR(i, 1, n) {
    int L = i, v; cin >> v;
    while(!s.empty() && s.back().v <= v)
      upd(s.back(), -1), L = s.back().l, s.pop_back();
    // cerr << "now = " << i << "\n";
    s.eb(node {L, i, v}), upd(s.back(), 1);
    // cout << bit::query(i) << " " << seg::query(i) << "\n";
    cout << bit::query(i) - seg::query(i) << " \n"[i == n];
  }
}
main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  while(cin >> n >> m) WORK();
  cerr << 1.0 * clock() / CLOCKS_PER_SEC;
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3 0
1 3 2
3 1
1 3 2
5 2
1 2 3 4 5
10 4
9 9 5 4 4 1 2 8 5 2
10 0
9 4 5 2 5 8 3 4 5 4
10 -2
5 10 10 3 6 6 10 2 4 5
10 0
1 10 2 5 8 3 7 2 2 3
10 8
10 1 4 8 8 4 2 1 6 2
10 -10
6 7 6 9 6 10 4 6 4 5
10 9
2 6 7 10 2 1 2 2 10 7
10 -6
8 9 2 10 7 2 1 8 6 1
10 8
6 10 2 8 1 7 8 8 8 9
10 -1
4 9 8 4 2 10 6 5 9 5
...

output:

1 2 3
0 2 2
0 0 1 2 3
1 2 3 2 2 1 0 4 4 2
1 2 3 4 5 6 7 8 9 8
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 1 0 0 0 0 0 0 0 0
1 2 3 4 5 6 7 8 9 10
0 0 0 1 0 0 0 0 1 0
1 2 3 4 5 6 7 8 9 10
0 2 1 0 0 0 0 0 0 1
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 3 5 6 5 4 3 4
1 2 3 4 5 6...

result: