QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#855653#9971. 新本格魔法少女りすかDengDuck0 10132ms21260kbC++142.5kb2025-01-13 06:19:472025-01-13 06:19:47

Judging History

This is the latest submission verdict.

  • [2025-01-13 06:19:47]
  • Judged
  • Verdict: 0
  • Time: 10132ms
  • Memory: 21260kb
  • [2025-01-13 06:19:47]
  • Submitted

answer

#include<bits/stdc++.h>
#define LL long long
#define uLL unsigned long long
#define pII pair<int,int>
using namespace std;
const int N=5e5+5,B=300;
int n,m,Cnt,A[N],RS[N],St[N];
LL Ans[N],S[N];
struct Line{int L,R;}Qry[N],F[N/B+5];
inline int Rd()
{
	int S=0;char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while('0'<=c&&c<='9')S=S*10+c-'0',c=getchar();
	return S;
}
int Ch[N];
#define LB(x) ((x)&(-x))
struct BIT
{
	uLL B[N];int t[N],n;
	inline void upd(int x)
	{
		Ch[++Ch[0]]=x;
		B[x>>6]|=1ull<<(x&63),x>>=6,x++;
		while(x<=n)t[x]++,x+=LB(x);
	}
	inline void cl(int x)
	{
		B[x>>=6]=0,x++;
		while(x<=n&&t[x])t[x]=0,x+=LB(x);
	}
	inline int qry(int x)
	{
		int S=__builtin_popcountll(B[x>>6]&(((x&63)==63?0:(1ull<<((x&63)+1)))-1));x>>=6;
		while(x)S+=t[x],x-=LB(x);
		return S;
	}
	inline LL Qry(int L,int R)
	{
		LL S=0;
		for(int i=L;i<=R;i++)S+=qry(A[i]-1);
		return S;
	}
	inline void Upd(int L,int R)
	{
		for(int i=L;i<=R;i++)upd(A[i]);
	}
	inline void Clear()
	{
		for(int i=1;i<=Ch[0];i++)cl(Ch[i]);
		Ch[0]=0;
	}
}T;
#define In(x) ((x-1)/B+1)
int main()
{
	n=Rd(),m=Rd();T.n=(n>>6)+1;
	for(int i=1;i<=In(n);i++)F[i]={F[i-1].R+1,min(i*B,n)};
	for(int i=1;i<=n;i++)A[i]=Rd();
	for(int i=1;i<=m;i++)
	{
		int t=Rd();St[i]=Cnt+1;
		for(int j=0,L,R;j<t;j++)
		{
			L=Rd(),R=Rd(),Qry[++Cnt]={L,R};
			int BL=In(L),BR=In(R);
			if(BL==BR)
			{
				if(R<F[BL].R||L>F[BL].L)Ans[i]+=T.Qry(L,R),T.Upd(L,R);
			}
			else
			{
				if(L>F[BL].L)Ans[i]+=T.Qry(L,F[BL].R);
				if(R<F[BR].R)Ans[i]+=T.Qry(F[BR].L,R);
				if(L>F[BL].L)T.Upd(L,F[BL].R);
				if(R<F[BR].R)T.Upd(F[BR].L,R);
			}
		}
		T.Clear();
	}
	St[m+1]=Cnt+1;
	for(int i=1;i<=In(n);i++)
	{
		for(int j=F[i].L;j<=F[i].R;j++)RS[A[j]]++;
		for(int j=1;j<=n;j++)RS[j]+=RS[j-1];
		int Len=F[i].R-F[i].L+1;
		for(int j=1;j<F[i].L;j++)S[j]=S[j-1]+Len-RS[A[j]];
		for(int j=F[i].L;j<=F[i].R;j++)S[j]=S[j-1];
		for(int j=F[i].R+1;j<=n;j++)S[j]=S[j-1]+RS[A[j]-1];
		for(int j=1;j<=n;j++)RS[j]=0;
		for(int j=1;j<=m;j++)
		{
			int f=0;LL Sum=0;
			for(int k=St[j];k<St[j+1];k++)
			{
				Line v=Qry[k];
				if(v.L<=F[i].L&&F[i].R<=v.R){f=1;continue;}
				if(v.R<=F[i].L)Sum+=S[v.R]-S[v.L-1];
				else
				{
					int L=v.L,R=v.R,BL=In(L),BR=In(R);
					if(BL==BR)
					{
						if(R<F[BL].R||L>F[BL].L)Sum+=S[R]-S[L-1];
						else
						{
							if(L>F[BL].L)Sum+=S[F[BL].R]-S[L-1];
							if(R<F[BR].R)Sum+=S[R]-S[F[BR].L-1];
						}
					}
				}
			}
			Ans[j]+=Sum*f;
		}
	}
	for(int i=1;i<=m;i++)printf("%lld\n",Ans[i]);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 10132ms
memory: 20924kb

input:

500000 50174
453952 363686 491616 32825 57465 422945 471561 73291 421205 416554 23295 133266 242225 330448 25039 340064 28713 465664 162059 323880 28978 273728 101338 161413 294941 214275 63951 267981 294251 202822 253124 272510 3268 37918 139343 385983 111577 311901 487665 482827 347449 416029 3065...

output:

36816370961
34305650893
43563907347
33943888502
43750499092
29111317627
41770186733
29001824285
34197713347
30790834285
44711437842
42354131721
24793081232
47638870664
39643655027
31736502642
31988649108
31719207554
44459837452
45764807380
34798785257
31185769543
33800480612
30314721177
43032421390
...

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 10
Accepted
time: 3637ms
memory: 21080kb

input:

500000 5
157360 289139 98034 293691 150262 268366 36782 147093 365410 444658 343224 375392 278298 357620 389673 167019 7747 119244 102126 83512 3649 459230 197365 245259 38071 249539 34617 213697 292553 389625 395778 280152 280038 239519 301475 232272 145919 370004 422791 271143 488283 185166 351026...

output:

50666226791
50440151159
50719090228
50631079493
50747050985

result:

ok 5 number(s): "50666226791 50440151159 50719090228 50631079493 50747050985"

Test #7:

score: 0
Wrong Answer
time: 3369ms
memory: 21260kb

input:

500000 5
70752 248917 41910 13653 177839 45858 54229 174152 10090 332231 437916 391622 432270 53875 446421 91921 461870 243336 363086 249844 338371 495447 423857 350363 365324 255747 170681 435791 177298 199582 240768 449011 302158 378518 233809 267343 362784 187864 114604 322031 255693 54447 406202...

output:

39141819031
38986160445
40132438929
38087302985
62373267184

result:

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

Subtask #3:

score: 0
Skipped

Dependency #1:

0%