QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#445518#8527. Power Divisionsucup-team3695#WA 6ms7968kbC++201.5kb2024-06-16 03:19:332024-06-16 03:19:34

Judging History

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

  • [2024-06-16 03:19:34]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:7968kb
  • [2024-06-16 03:19:33]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair

#define MAXN 300'010

#define MAXM 1'000'010

const ll mod = 1e9 + 7;

int n;

int a[MAXN];
vi hasthing[MAXM];

vi intervals[MAXN];

int memo[MAXN][2];

ll mem[MAXN];


int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	cin >> n;
	rep(i, 0, n) {
		cin >> a[i];
		hasthing[a[i]].pb(i);
	}

	vi poss;
	vi poss2;
	rep(i, 0, n) rep(j, 0, 2) memo[i][j] = -1;
	rep(i, 0, n) {
		if (a[i] == 0) {
			memo[i][0] = i;
			poss.pb(i);
			intervals[i].pb(i);
		}
	}

	rep(amt, 1, MAXM) {
		int ind = amt % 2;
		int prevind = (ind+1)%2;

		poss2.clear();

		for (int x : hasthing[amt]) {
			memo[x][ind] = x;
			poss2.pb(x);
			intervals[x].pb(x);
		}

		for (int x : poss) {
			int ending = memo[x][prevind];
			if (ending < n-1 && memo[ending+1][prevind] != -1) {
				poss2.pb(x);
				memo[x][ind] = memo[ending+1][prevind];
				intervals[memo[ending+1][prevind]].pb(x);
			}
		}


		for (int x : poss) {
			memo[x][prevind] = -1;
		}

		poss = poss2;	
	}


	rep(i, 0, n) {
		mem[i] = 0;
		for (int x : intervals[i]) {
			if (x == 0) {
				mem[i] += 1;
				mem[i] %= mod;
			} else {
				mem[i] += mem[x-1];
				mem[i] %= mod;
			}
		}
	}
	cout << mem[n-1] << endl;
	

}

詳細信息

Test #1:

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

input:

5
2 0 0 1 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 6ms
memory: 7968kb

input:

1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 5ms
memory: 7732kb

input:

2
1 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 5ms
memory: 7672kb

input:

3
2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #5:

score: 0
Accepted
time: 5ms
memory: 5692kb

input:

4
3 2 2 3

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

5
3 4 4 2 4

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: -100
Wrong Answer
time: 5ms
memory: 7704kb

input:

7
3 4 3 5 6 3 4

output:

1

result:

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