QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#351355#7899. Say Hello to the FutureoscaryangWA 333ms102792kbC++203.5kb2024-03-11 20:59:252024-03-11 20:59:26

Judging History

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

  • [2024-03-11 20:59:26]
  • 评测
  • 测评结果:WA
  • 用时:333ms
  • 内存:102792kb
  • [2024-03-11 20:59:25]
  • 提交

answer

#include<bits/stdc++.h>

#define vc vector
#define pb emplace_back
#define pii pair<int, int>
#define mkp make_pair
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define lep(i, a, b) for(int i = (a); i >= (b); --i)

#define int long long

using namespace std;

inline int read() {
	int x = 0, w = 0; char ch = getchar(); while(!isdigit(ch)) w |= (ch == '-'), ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return w ? -x : x; 
}

const int N = 2e5 + 5, LOG = 20;

namespace sgt {
	int lc[N * LOG], rc[N * LOG], tre[N * LOG], rt[N], idx;
	#define mid (l + r >> 1)
	inline int newnode() { ++idx; lc[idx] = rc[idx] = tre[idx] = 0; return idx; }
	inline void ins(int &k, int pr, int l, int r, int p, int v) {
		k = newnode(); lc[k] = lc[pr]; rc[k] = rc[pr]; tre[k] = tre[pr] + v;
		if(l != r) return p <= mid ? ins(lc[k], lc[pr], l, mid, p, v) : ins(rc[k], rc[pr], mid + 1, r, p, v);
	}
	inline int ask(int k, int l, int r, int L, int R) {
		if(!k || L > R || l > R || r < L) return 0;
		if(L <= l && R >= r) return tre[k];
		return ask(lc[k], l, mid, L, R) + ask(rc[k], mid + 1, r, L, R);
	}
}
using namespace sgt;

int n, a[N], b[N], f[N], g[N], dp[N];	

inline void solvef(int l, int r) {
	if(l == r) return ;
	solvef(l, mid);
	
	rep(i, l, r) rt[i] = b[i] = 0; idx = 0;
	lep(i, mid - 1, l) b[i] = max(b[i + 1], a[i + 1]);
	rep(i, mid + 1, r) b[i] = max(b[i - 1], a[i]);
	
	rep(i, l, mid) {
		rt[i] = i > l ? rt[i - 1] : 0;
		if(i + b[i] <= r) ins(rt[i], rt[i], 0, n, i + b[i], f[i]);
	}
	rep(i, mid + 1, r) 
		if(i - b[i] >= l) f[i] += ask(rt[min(mid, i - b[i])], 0, n, 0, i);
	
	solvef(mid + 1, r);
}

inline void solveg(int l, int r) {
	if(l == r) return ;
	solveg(mid + 1, r);
	
	rep(i, l, r) rt[i] = b[i] = 0; idx = 0;
	lep(i, mid - 1, l) b[i] = max(b[i + 1], a[i + 1]);
	rep(i, mid + 1, r) b[i] = max(b[i - 1], a[i]);
	
	lep(i, r, mid + 1) {
		rt[i] = i < r ? rt[i + 1] : 0;
		if(i - b[i] >= l) ins(rt[i], rt[i], 0, n, i - b[i], g[i]);
	}
	lep(i, mid, l) 
		if(i + b[i] <= r) g[i] += ask(rt[max(mid + 1, i + b[i])], 0, n, i, n);
		
	solveg(l, mid);
}

inline void solvedp(int l, int r) {
	if(l == r) return ;
	solvedp(l, mid); solvedp(mid + 1, r);
	
	rep(i, l, r) rt[i] = b[i] = 0; idx = 0;
	lep(i, mid - 1, l) b[i] = max(b[i + 1], a[i + 1]);
	rep(i, mid + 1, r) b[i] = max(b[i - 1], a[i]);
	rep(i, l, mid) {
		rt[i] = i > l ? rt[i - 1] : 0;
		if(i + b[i] <= r) ins(rt[i], rt[i], 0, n, i + b[i], f[i]);
	}
	lep(i, r, mid + 1) {
		rt[i] = i < r ? rt[i + 1] : 0;
		if(i - b[i] >= l) ins(rt[i], rt[i], 0, n, i - b[i], g[i]);
	}
	
	for(int i = mid + 1, mx = 0, val = 0, j; i <= r; i++) {
		if(a[i] > mx) val = mx, mx = a[i], j = i;
		val = max(val, i == j ? 1 : a[i]);
		if(i - b[i] >= l) dp[j] -= ask(rt[min(mid, i - b[i])], 0, n, 0, i) * g[i];
		if(i - val  >= l) dp[j] += ask(rt[min(mid, i - val)] , 0, n, 0, i) * g[i];
	}
	for(int i = mid, mx = 0, val = 0, j = 0; i >= l; i--) {
		if(j && i + b[i] <= r) dp[j] -= ask(rt[max(mid + 1, i + b[i])], 0, n, i, n) * f[i];
		if(j && i - val  <= r) dp[j] += ask(rt[max(mid + 1, i + val)] , 0, n, i, n) * f[i];
		if(a[i] > mx) val = mx, mx = a[i], j = i;
		val = max(val, i == j ? 1 : a[i]);
	} 
}

signed main() {
	n = read(); 
	rep(i, 1, n) a[i] = read();
	
	f[0] = 1; solvef(0, n);
	g[n] = 1; solveg(0, n);
	// rep(i, 0, n) cerr << i << " " << f[i] << " " << g[i] << endl;
	solvedp(0, n);
	
	rep(i, 1, n) printf("%lld%c", f[n] + dp[i], " \n"[i == n]);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 18216kb

input:

5
1 3 2 1 2

output:

3 6 3 3 6

result:

ok 5 tokens

Test #2:

score: -100
Wrong Answer
time: 333ms
memory: 102792kb

input:

200000
15922 15391 11782 4758 1973 19909 16800 6438 3821 986 18599 2011 338 19886 12401 4169 11143 12665 3230 12565 15065 15056 5090 16908 13677 12634 11435 1425 8647 3876 10694 12256 3853 19901 5723 11065 6147 13613 13768 15794 14993 5819 8117 13871 14708 15099 7152 9810 14438 10557 3209 1265 13915...

output:

-8366584534638002176 6344407257362464768 6344407257362464768 6344407257362464768 6344407257362464768 -5181156341793685504 6344407257362464768 6344407257362464768 6344407257362464768 6344407257362464768 6344407257362464768 6344407257362464768 6344407257362464768 6344407257362464768 634440725736246476...

result:

wrong answer 1st words differ - expected: '157122482', found: '-8366584534638002176'