QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#240609 | #7457. rvrewsus | Crysfly | 11 | 2240ms | 182988kb | C++17 | 3.9kb | 2023-11-05 16:49:52 | 2023-11-05 16:49:53 |
Judging History
answer
// what is matter? never mind.
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
using namespace std;
inline ll read()
{
char c=getchar();ll x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 200005
#define inf 0x3f3f3f3f
#define mod 333333333333333397
#define ull unsigned long long
int n,m,t,B,id[maxn],cnt[maxn];
int lx[maxn],rx[maxn],ly[maxn],ry[maxn];
ll a[maxn],b[maxn];
ll pw[maxn],w;
vi p[maxn];
inline ll ksc(ll x,ll y,ll zz){
ll z=(long double)x/mod*y;
ll res=(ull)x*y-(ull)z*mod;
return (res+zz+mod)%mod;
}
inline ll add(ll x,ll y){
return ((x+=y)>=mod)?(x-mod):(x);
}
struct dat{
ll x; int y;
dat(ll a=0,int b=0){x=a,y=b;}
void operator +=(dat b){
x=ksc(b.x,pw[y],x);
y+=b.y;
}
};
dat res[maxn];
int tot,su[maxn];
vi pos[2005];
vector<vector<dat>>f[2005];
int idl[maxn],idr[maxn];
int merge(int u,int v){
if(!u||!v)return u|v;
int x=++tot;
pos[x].resize(pos[u].size()+pos[v].size());
merge(pos[u].begin(),pos[u].end(),pos[v].begin(),pos[v].end(),pos[x].begin());
int szx=pos[x].size(),szu=pos[u].size(),szv=pos[v].size(),t=0;
For(i,0,szx-1){
while(t<szu && pos[u][t]<pos[x][i]) ++t;
idl[i]=t;
}
t=szu-1;
Rep(i,szx-1,0){
while(t>=0 && pos[u][t]>pos[x][i]) --t;
idr[i]=t;
}
f[x].resize(szx);
For(l,0,szx-1){
f[x][l].resize(szx);
For(r,l,szx-1)
if(idl[l]<szu && idr[r]>=0) f[x][l][r]=f[u][idl[l]][idr[r]];
else f[x][l][r]=dat();
}
t=0;
For(i,0,szx-1){
while(t<szv && pos[v][t]<pos[x][i]) ++t;
idl[i]=t;
}
t=szv-1;
Rep(i,szx-1,0){
while(t>=0 && pos[v][t]>pos[x][i]) --t;
idr[i]=t;
}
For(l,0,szx-1)
For(r,l,szx-1)
if(idl[l]<szv && idr[r]>=0)
f[x][l][r]+=f[v][idl[l]][idr[r]];
return x;
}
int build(int l,int r){
if(l>r)return 0;
if(l==r){
int x=++tot;
pos[x].resize(cnt[l]);
f[x].resize(cnt[l]);
For(i,0,cnt[l]-1)pos[x][i]=p[l][i];
For(i,0,cnt[l]-1){
f[x][i].resize(cnt[l]);
For(j,i,cnt[l]-1)f[x][i][j]=dat(b[l],1);
}
return x;
}
int mid=l;
For(i,l+1,r)
if(max(su[i]-su[l-1],su[r]-su[i-1])<max(su[mid]-su[l-1],su[r]-su[mid-1])) mid=i;
return merge(merge(build(l,mid-1),build(mid,mid)),build(mid+1,r));
}
void work(int l,int r){
tot=0;
int x=build(l,r);
int t=0,szx=pos[x].size();
For(i,1,n){
while(t<szx && pos[x][t]<i) ++t;
idl[i]=t;
}
t=szx-1;
Rep(i,n,1){
while(t>=0 && pos[x][t]>i) --t;
idr[i]=t;
}
For(i,1,m){
if(ry[i]<l||ly[i]>r)continue;
if(ly[i]<=l&&ry[i]>=r){
if(idl[lx[i]]<=idr[rx[i]])
res[i]+=f[x][idl[lx[i]]][idr[rx[i]]];
continue;
}
int L=max(l,ly[i]),R=min(r,ry[i]);
For(j,L,R){
// auto it=lower_bound(p[j].begin(),p[j].end(),lx[i]);
// if(it!=p[j].end() && (*it)<=rx[i]) res[i]+=dat(b[j],1);
}
}
}
int sums[maxn];
void brute(int x){
For(i,1,n)sums[i]=sums[i-1]+(id[i]==x);
For(i,1,m)
if(ly[i]<=x&&ry[i]>=x&&sums[rx[i]]!=sums[lx[i]-1]) res[i]+=dat(b[x],1);
}
signed main()
{
// freopen("my.out","w",stdout);
n=read(),w=read(),m=read();
*pw=1;
For(i,1,n)pw[i]=(__int128)pw[i-1]*w%mod;
For(i,1,n)a[i]=b[i]=read();
sort(b+1,b+n+1),t=unique(b+1,b+n+1)-b-1;
For(i,1,n){
id[i]=lower_bound(b+1,b+t+1,a[i])-b;
p[id[i]].pb(i),++cnt[id[i]];
}
For(i,1,m){
lx[i]=read(),rx[i]=read();
ll L=read(),R=read();
ly[i]=lower_bound(b+1,b+t+1,L)-b;
ry[i]=upper_bound(b+1,b+t+1,R)-b-1;
}
B=sqrt(n)*0.8;
For(i,1,t)su[i]=su[i-1]+cnt[i];
For(l,1,t){
if(cnt[l]>B){brute(l);continue;}
int r=l;
while(r+1<=t && su[r+1]-su[l-1]<=2*B) ++r;
work(l,r);
l=r;
}
For(i,1,m)printf("%lld\n",res[i].x);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 2
Accepted
time: 0ms
memory: 22164kb
input:
5 33333333333333333 5 333 33 333 33333 3 4 5 3 333333 2 4 3 333333 1 3 3 333333 1 5 3 333333 4 4 3 333333
output:
99999999999776691 30000000001494126 99999999999997821 332333333323322794 33333
result:
ok 5 number(s): "99999999999776691 300000000014...997821 332333333323322794 33333"
Test #2:
score: -2
Wrong Answer
time: 0ms
memory: 22520kb
input:
33 33333 33 333333333 333333333333 33333333333333 33333333333 33333 333333333333333 33 333 333 333333 3 333333333 3333333 3 333333333 33333333333333 333333333333333 33333333333333 333333 33333333333333 33333333333333 33333333 333333333333333 33333333 33333333 33333 33333333 3333333 33333333 33333333...
output:
5381244831822484 11111003322222 33333333333333 17246771605537406 37036407039959259 1111103322222 70337133069920353 111033333333320121 1111100333322222 296311110655885383 259223255302742554 155540455597373668 308619740796621715 11111000333322222 0 0 37029740406625862 33333333333333 70337133069920353 ...
result:
wrong answer 4th numbers differ - expected: '187453349930639529', found: '17246771605537406'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 2105ms
memory: 182988kb
input:
200000 107782444907597493 200000 307079331392938370 307079331392968097 307079331392903815 307079331392954135 307079331392921120 307079331392922133 307079331392960650 307079331392904239 307079331392924042 307079331392965983 307079331392926310 307079331392954306 307079331392922324 307079331392899589 3...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 1st numbers differ - expected: '161955485578140740', found: '0'
Subtask #4:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 2240ms
memory: 134972kb
input:
200000 1 200000 125770169940402588 125770169937831780 125770169933800218 125770169942553950 125770169934974373 125770169938644434 125770169941807845 125770169941152047 125770169941701823 125770169933616443 125770169941027577 125770169934451401 125770169934151641 125770169942154386 125770169943254896...
output:
183588557810374555 634428976673858 211498042103858482 165572344078445826 310737562672454179 276996320976939996 34780135266734587 101757727398652161 173214406691056128 46205070731049732 48026331850424428 85513268229362313 144989058502796907 111752130734428009 132855568193119211 34516709357335633 1013...
result:
wrong answer 1st numbers differ - expected: '295340688837008705', found: '183588557810374555'
Subtask #5:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 1728ms
memory: 50036kb
input:
200000 266366343650001951 200000 141484782917791581 3787263978285804 226597267432839715 116805584657282964 1672627344197059 193206512378213612 177708049680616340 258561444587530831 327277782165386753 199630894972945384 189627118906507559 195173317940439913 304797836288090181 26239031738473735 196441...
output:
202647768165371853 290613032023774113 331451593777072710 190093363770841934 0 63137170686859594 218601970673585002 306966204703188431 314813849487863799 102068438272979222 322887800959537305 218260283291798474 25077473582098643 165147052738009685 288711948284175011 13129710964856326 7621921271003376...
result:
wrong answer 1st numbers differ - expected: '18499401057027185', found: '202647768165371853'
Subtask #6:
score: 11
Accepted
Test #8:
score: 11
Accepted
time: 2181ms
memory: 65900kb
input:
200000 50792913662035090 200000 269588051930761680 225425839878809771 262122420471176797 203473734848800544 136809413887071259 318701071182600442 8727498636252904 241189169763894674 312419425866995439 138524629339646322 12022562549235759 290999362274438984 272430547010050450 90278514401605935 711452...
output:
277531772563993023 53612358852863908 178661541991608658 6319390503872082 98290644097639729 146368503555863844 304776783168292527 203668217042126594 331361768603699997 255867936832118569 72400407952991626 105283252295457149 256323674949484514 67689171661792967 191459148202533888 165254129987700124 38...
result:
ok 200000 numbers
Subtask #7:
score: 0
Skipped
Dependency #1:
0%