QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#670801#7685. Barkley IISredWA 135ms3644kbC++17974b2024-10-24 01:45:232024-10-24 01:45:23

Judging History

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

  • [2024-10-24 01:45:23]
  • 评测
  • 测评结果:WA
  • 用时:135ms
  • 内存:3644kb
  • [2024-10-24 01:45:23]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e6 + 5;
const int inf = 2e6;
int f[maxn],a[maxn];
int n,m;
int lowbit(int k){
	 return k&(-k);
}
void add(int i,int k){
	for(;i <= m*2;i += lowbit(i)) f[i] += k;
}
int find(int i){
	int ans = 0;
	for(;i >= 1; i-= lowbit(i)) ans += f[i];
	return ans;
	
}
map<int,int> mp; 
void solve(){
	
	
	cin >> n >> m;
	int ans = -1;
 	for(int i = 1 ;i <= n ;i ++) {
 		cin >> a[i];
 	}
	for(int i = 1;i <= n ;i ++){
		
		ans = max(ans,find(i) - find(mp[a[i]]) - a[i]);
		if(mp[a[i]]) add(mp[a[i]],-1);
		add(i,1);
		mp[a[i]] = i;
		
	}
	for(int i = 1;i <= n ;i ++){
		    ans = max(ans,find(n) - find(mp[a[i]]) - a[i]); 
	}
	for(int i = 1;i <= n;i ++){
		 if(mp[a[i]]){
            add(i,-1);
        }
		 mp[a[i]] = 0;
	}
	cout << ans <<endl;
} 
signed main() {
    int t = 1;
   cin >> t;
    while (t--) {
       solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3644kb

input:

2
5 4
1 2 2 3 4
5 10000
5 2 3 4 1

output:

2
3

result:

ok 2 number(s): "2 3"

Test #2:

score: -100
Wrong Answer
time: 135ms
memory: 3624kb

input:

50000
10 19
12 6 1 12 11 15 4 1 13 18
10 8
8 7 6 7 6 2 2 3 4 8
10 6
3 2 6 6 5 2 3 4 5 6
10 11
6 3 7 9 2 1 2 10 10 4
10 6
6 1 2 6 1 1 3 4 2 1
10 9
8 5 3 9 1 7 5 5 1 1
10 5
1 4 3 2 5 4 5 3 5 2
10 14
3 8 12 10 4 2 3 13 7 3
10 14
5 5 12 2 8 1 13 9 8 5
10 7
5 5 6 6 1 5 3 7 3 4
10 7
5 1 4 6 1 6 4 3 7 5
10...

output:

3
2
5
8
9
12
10
15
18
21
23
18
17
27
23
24
30
22
38
32
31
37
41
40
37
43
44
45
46
51
46
29
55
59
53
60
61
57
63
65
69
68
70
66
74
73
68
75
76
82
81
80
82
79
79
89
92
95
90
87
89
100
87
98
99
102
100
110
107
105
104
104
109
111
118
116
109
125
126
121
124
126
120
123
116
136
131
135
134
139
140
139
1...

result:

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