QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#53136 | #4808. Great Party | Silent_Ash | WA | 0ms | 3476kb | C++ | 1.8kb | 2022-10-04 19:11:49 | 2022-10-04 19:11:52 |
Judging History
answer
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll ;
const int N = 1e6 + 5 ;
const int BIT = 1 << 18 ;
int rd()
{
int res = 0 , f = 1 ;
char ch = getchar();
while(ch < '0' || ch > '9'){if(ch == '-')f = -1 ; ch = getchar() ;}
while(ch >= '0' && ch <= '9')res = (res << 1) + (res << 3) + (ch ^ 48) , ch = getchar() ;
return res * f ;
}
int n , q , sq ;
struct Q
{
int l , r , p ;
Q(){}
Q(int a , int b , int c):l(a),r(b),p(c){};
bool operator < (Q q) const
{
if(l / sq != q.l / sq) return l / sq < q.l / sq ;
return r > q.r ;
}
~Q(){}
}que[N] ;
int a[N] , pre[N] , ans[N] ;
int cnt[N * 7] , sum , l = 1 , r = 1 ;
int C2(int n){return n / 2.0 * (n - 1) ;}
void del(int p)
{
sum -= C2(cnt[pre[p]]--) ;
sum += C2(cnt[pre[p]]) ;
}
void add(int p)
{
sum -= C2(cnt[pre[p]]++) ;
sum += C2(cnt[pre[p]]) ;
}
int query(int ql , int qr)
{
while(l > ql) add(--l) ;
while(r < qr) add(++r) ;
while(l < ql) del(l++) ;
while(r > qr) del(r--) ;
return sum ;
}
int main()
{
n = rd() ; q = rd() ; sq = sqrt(n) ;
// for(int i = 1 ; i <= n ; i++)
// a[i] = rd() ;
for(int i = 1 ; i <= n ; i++)
pre[i] = pre[i - 1] ^ (rd() - 1 | BIT) ;
for(int i = 1 ; i <= q ; i++)
{
int a = rd() - 1 , b = rd() ;
que[i] = Q(a , b , i) ;
}
// for(int i = 1 ; i <= q ; i++)
// que[i] = Q(rd() - 1 , rd() , i) ;
sort(que + 1 , que + 1 + q) ;
for(int i = 1 ; i <= q ; i++)
// cout << que[i].l << ' ' << que[i].r << ' ' << que[i].p << '\n' ,
ans[que[i].p] = C2(que[i].r - que[i].l + 1) - query(que[i].l , que[i].r) ;
for(int i = 1 ; i <= q ; i++)
cout << ans[i] << '\n' ;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3476kb
input:
4 5 1 2 2 4 1 2 2 3 3 4 1 3 2 4
output:
3 3 3 6 6
result:
wrong answer 2nd numbers differ - expected: '2', found: '3'