Submission #1054899

#TimeUsernameProblemLanguageResultExecution timeMemory
1054899inesfiAddk (eJOI21_addk)C++14
92 / 100
77 ms9812 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define endl "\n" const int DECALAGE=(1<<17); int nbpers,nbpermut,nbquest,val,l,r,m,rep; int arbre[DECALAGE*2][3]; int somme(int a,int b,int tab){ if (b<a){ return 0; } if (a==b){ return arbre[a][tab]; } if (a%2==1){ return arbre[a][tab]+somme(a+1,b,tab); } if (b%2==0){ return arbre[b][tab]+somme(a,b-1,tab); } return somme(a/2,b/2,tab); } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>nbpers>>nbpermut; for (int i=0;i<nbpers;i++){ cin>>arbre[i+DECALAGE][1]; arbre[i+DECALAGE][0]=arbre[i+DECALAGE][1]*(i+1); arbre[i+DECALAGE][2]=arbre[i+DECALAGE][1]*(nbpers-i); } for (int i=DECALAGE-1;i>=0;i--){ for (int j=0;j<3;j++){ arbre[i][j]=arbre[i*2][j]+arbre[i*2+1][j]; } } cin>>nbquest; for (int iquest=0;iquest<nbquest;iquest++){ cin>>val; if (val==2){ cin>>l>>r>>m; l--; r--; //cout<<somme(l+DECALAGE,r+DECALAGE,1)<<endl; rep=somme(l+DECALAGE,min(l+m-2,r-m)+DECALAGE,0)-somme(l+DECALAGE,min(l+m-2,r-m)+DECALAGE,1)*l; //cout<<l<<" "<<min(l+m-2,r-m)<<" "<<rep<<endl; rep+=somme(min(l+m-2,r-m)+1+DECALAGE,max(l+m,r-m+2)-1+DECALAGE,1)*min(m,r-l-m+2); //cout<<min(l+m-2,r-m)+1<<" "<<max(l+m,r-m+2)-1<<" "<<rep<<endl; //cout<<m<<endl; rep+=somme(max(l+m,r-m+2)+DECALAGE,r+DECALAGE,2)-somme(max(l+m,r-m+2)+DECALAGE,r+DECALAGE,1)*(nbpers-r-1); //cout<<max(l+m,r-m+2)<<" "<<r<<" "<<rep<<endl; cout<<rep<<endl; } else { for (int i=0;i<nbpermut;i++){ cin>>val; } } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...