QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#735677 | #9482. Count Pseudo-Palindromes | NKheyuxiang | WA | 1893ms | 76980kb | C++14 | 1.2kb | 2024-11-11 21:14:16 | 2024-11-11 21:14:17 |
Judging History
answer
#include<bits/stdc++.h>
#define N 1000005
#define ull unsigned long long
#define gc (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++)
using namespace std;
char buf[100000], *p1, *p2;
inline int read(){
char ch;
int x = 0;
while ((ch = gc) < 48);
do x = x * 10 + ch - 48; while ((ch = gc) >= 48);
return x;
}
int n,a[N],b[N],c[N];
ull shift(ull x){
x^=(x<<11);
x^=(x>>4);
x^=(1<<5);
x^=(1>>14);
return x;
}
ull s[N];
set<int > st;
unordered_map<int ,int > mp;
long long ans[N];
int main(){
n=read();
for(int i=1;i<=2*n;i++){
a[i]=read();
if(c[a[i]]) b[c[a[i]]]=i,b[i]=c[a[i]];
c[a[i]]=i;
}
for(int i=1;i<=2*n;i++) s[i]=s[i-1]^shift(a[i]);
for(int i=1;i<=2*n;i++){
mp[s[i-1]]++;
if(i<b[i]) st.insert(i);
else st.erase(b[i]);
if(!st.empty()){
auto it=st.end();it--;
ans[*it]+=mp[s[i]^shift(a[*it])];
}
}
mp.clear();st.clear();
for(int i=2*n;i>=1;i--){
mp[s[i]]++;
if(i>b[i]) st.insert(i);
else st.erase(b[i]);
if(!st.empty()){
auto it=st.begin();
ans[*it]+=mp[s[i-1]^shift(a[*it])];
}
}
for(int i=1;i<=2*n;i++) printf("%lld ",ans[i]);
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 9888kb
input:
2 1 1 2 2
output:
1 2 2 1
result:
ok 4 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 9892kb
input:
3 2 1 2 3 1 3
output:
1 2 2 2 2 1
result:
ok 6 tokens
Test #3:
score: 0
Accepted
time: 0ms
memory: 9896kb
input:
4 1 2 4 3 4 1 3 2
output:
1 2 1 2 1 3 1 1
result:
ok 8 tokens
Test #4:
score: 0
Accepted
time: 2ms
memory: 10172kb
input:
1 1 1
output:
1 1
result:
ok 2 tokens
Test #5:
score: -100
Wrong Answer
time: 1893ms
memory: 76980kb
input:
500000 233733 151347 468353 495903 234861 297169 312993 2734 287872 359375 79017 285205 219439 37290 409190 194953 306816 472906 123794 121028 66509 62235 385879 300188 485875 72413 167304 333428 33910 220100 151575 22575 206653 82054 111518 34032 48702 198940 6262 222529 170641 1735 38943 235003 11...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
wrong answer 906th words differ - expected: '1', found: '512'