QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#335513 | #1856. Interval | AFewSuns | AC ✓ | 269ms | 44956kb | C++14 | 3.0kb | 2024-02-23 15:16:12 | 2024-02-23 15:16:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define ll long long
#define bl bool
ll my_pow(ll a,ll b,ll mod){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
ll qpow(ll a,ll b){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res*=a;
a*=a;
b>>=1;
}
return res;
}
#define db double
#define pf printf
#define pc putchar
#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
#define go(u) for(ll i=head[u];i;i=e[i].nxt)
#define enter pc('\n')
#define space pc(' ')
#define fir first
#define sec second
#define MP make_pair
#define il inline
#define inf 8e18
#define random(x) rand()*rand()%(x)
#define inv(a,mod) my_pow((a),(mod-2),(mod))
il ll read(){
ll sum=0,f=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch)){
sum=sum*10+(ch^48);
ch=getchar();
}
return sum*f;
}
il void write(ll x){
if(x<0){
x=-x;
pc('-');
}
if(x>9) write(x/10);
pc(x%10+'0');
}
il void writeln(ll x){
write(x);
enter;
}
il void writesp(ll x){
write(x);
space;
}
}
using namespace my_std;
#define mod 998244353
set<pair<pair<ll,ll>,ll> > s;
vector<pair<ll,ll> > vec[200020],qry[200020];
ll n,m,ans[200020];
struct BIT{
ll tree[200020];
il ll lowbit(ll x){
return x&(-x);
}
il void mdf(ll x,ll v){
while(x){
tree[x]=(tree[x]+v)%mod;
x-=lowbit(x);
}
}
il ll query(ll x){
ll res=0;
while(x<=n){
res=(res+tree[x])%mod;
x+=lowbit(x);
}
return res;
}
}T1,T2,T3,T4;
int main(){
n=read();
m=read();
s.insert(MP(MP(-inf,inf),0));
fr(i,1,n){
ll l=read(),r=read();
vec[i].push_back(MP(i,r-l));
set<pair<pair<ll,ll>,ll> >::iterator it=--s.upper_bound(MP(MP(l+1,-inf),-inf));
while(it!=s.end()){
pair<pair<ll,ll>,ll> now=*it;
if(now.fir.sec<=l){
it++;
continue;
}
if(now.fir.fir>=r) break;
ll L=max(now.fir.fir,l),R=min(now.fir.sec,r);
vec[i].push_back(MP(now.sec,(L-R+mod)%mod));
s.erase(now);
if(now.fir.fir<L) s.insert(MP(MP(now.fir.fir,L),now.sec));
if(R<now.fir.sec) s.insert(MP(MP(R,now.fir.sec),now.sec));
it=s.upper_bound(now);
}
s.insert(MP(MP(l,r),i));
}
fr(i,1,m){
ll l=read(),r=read();
qry[r].push_back(MP(l,i));
}
fr(i,1,n){
fr(j,0,(ll)vec[i].size()-1){
T1.mdf(vec[i][j].fir,(mod-vec[i][j].sec)%mod);
T2.mdf(vec[i][j].fir,vec[i][j].sec*vec[i][j].fir%mod);
T3.mdf(vec[i][j].fir,vec[i][j].sec*i%mod);
T4.mdf(vec[i][j].fir,vec[i][j].sec*(mod-i)%mod*vec[i][j].fir%mod);
}
fr(j,0,(ll)qry[i].size()-1){
ll l=qry[i][j].fir,len=i-l+1,res=0;
res=(res+T1.query(l)*(i+1)%mod*(l-1))%mod;
res=(res+T2.query(l)*(i+1))%mod;
res=(res+T3.query(l)*(l-1))%mod;
res=(res+T4.query(l))%mod;
ans[qry[i][j].sec]=res*inv((len*(len+1)/2)%mod,mod)%mod;
}
}
fr(i,1,m) writeln(ans[i]);
}
/*
2 1
1 5
4 8
1 2
ans:
5
*/
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 13084kb
input:
2 1 1 5 4 8 1 2
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 257ms
memory: 44884kb
input:
200000 200000 4455910 81388645 47311584 83266871 2302533 83282606 37122147 63131823 54323252 71482325 24756264 89591670 24683722 45216831 3664402 90722731 20344438 58063424 18767188 61197540 44999082 54242932 20654464 60691742 7958498 88508082 24272079 25874809 63258707 70661986 48698861 63769448 40...
output:
149335631 625872899 209671594 397057221 578135657 297831629 94774378 307772432 239408309 471895751 669425606 877865414 844752350 718252313 836967965 783715970 104202952 267797959 230943760 353441337 534943711 898629127 202447492 482139796 584565257 643363500 741398873 973335212 218908116 460246124 7...
result:
ok 200000 lines
Test #3:
score: 0
Accepted
time: 254ms
memory: 44880kb
input:
200000 200000 59472069 72972050 67908358 77047425 72985575 81651787 6315811 61861426 41660138 92416481 51151414 99016704 49510155 88049625 52884542 81112319 19816189 96600746 58031429 74819750 29166518 42319726 37496143 75799252 30272355 58818291 9729644 33936326 50525873 89343595 31288675 72984939 ...
output:
112873395 229817 988723202 209421734 745689826 947849797 685595348 857351159 181551093 725880374 947697873 720715142 994518160 151380496 199199272 43615950 218276212 760766804 280524477 682383588 191232801 842292816 816219832 594681440 142319050 96178971 65822454 41925046 760523490 43249520 97205229...
result:
ok 200000 lines
Test #4:
score: 0
Accepted
time: 253ms
memory: 44948kb
input:
200000 200000 37555493 51553599 21084875 98570539 15776848 17464352 41890305 49499799 18383340 23964320 12711157 78309847 24079692 25849716 3784429 74854865 74063747 79848469 48250473 57104182 54347000 89383475 45682569 59370526 52586212 88937011 35378697 47030547 42825744 67833715 38999389 42495210...
output:
565033852 332437760 156535590 138787030 565880941 286297488 546191115 446725790 256121294 221277536 760535169 34574065 187812436 451881429 130034003 462576461 492194139 377205957 442879990 534004726 300187126 189615467 416675976 408385577 708755163 474147579 721036491 982388787 852172823 180621588 2...
result:
ok 200000 lines
Test #5:
score: 0
Accepted
time: 254ms
memory: 44940kb
input:
200000 200000 20069739 20671621 19898132 69424209 56910425 95126102 71662289 92683787 1235799 39317496 52570287 69238197 48906126 63649806 42049381 86265050 63096191 78568201 16648491 96368422 36447223 74494778 60790078 81244910 64279923 79932773 5348961 15803558 35125614 96580731 11551319 66781288 ...
output:
724483386 910778667 377502738 994436646 282430821 402168134 422964586 138416407 556222774 437130406 600372704 306343249 873386285 528321227 868835380 160898919 164236479 578321514 801905009 636165147 943369357 702806298 746991879 712823617 275148907 689327977 827518592 551184819 681947607 10065067 7...
result:
ok 200000 lines
Test #6:
score: 0
Accepted
time: 256ms
memory: 44936kb
input:
200000 200000 93618583 98755045 86390 13678686 24218459 46613393 40900479 46658464 60251651 88572685 26830726 85573749 6482600 28508367 63712967 64019704 32815759 91568106 40665367 85046509 28735164 94642555 43310781 75897588 2246630 34590131 13410478 96228418 27425484 70038148 31258855 79070545 319...
output:
119292102 76646473 231491193 370840742 573509871 826867498 944525207 901749239 295385734 611922675 911777486 621230888 955469824 189475929 545409242 207879002 568490237 129722490 726161240 13582391 481392157 156560919 713793467 556195632 268276421 17879964 411257428 808789178 248519797 848074039 633...
result:
ok 200000 lines
Test #7:
score: 0
Accepted
time: 259ms
memory: 44956kb
input:
200000 200000 21943236 76838469 25715868 52683432 3567713 86059466 76430447 79051763 70876867 86218511 6123870 47133492 53334800 99058498 41160884 85990027 37320214 74815828 34705416 63509935 64533437 75798912 65185164 96037801 24560487 59676148 21877471 26504699 14692651 93752460 60577637 91813963 ...
output:
248021684 805053852 723969855 522455751 750894085 2216616 689586368 387641653 906107416 42489193 5511026 474744178 206514842 263657114 78009513 452091392 197725511 4429041 664765225 121173208 907816208 510532332 933758056 838237676 578822584 144241833 21453022 474961381 980707568 409058152 996334953...
result:
ok 200000 lines
Test #8:
score: 0
Accepted
time: 240ms
memory: 44732kb
input:
200000 200000 54921893 90459376 51345346 51496689 35570947 82916966 11235134 22235751 7152666 48148346 8693236 30127414 27904337 36858589 18608801 48151838 13353151 96600476 31907953 73969657 27895365 89713919 60888414 82026843 35019060 56939752 2302332 39598920 6992521 72242580 30087907 59333189 26...
output:
560021271 779167220 815231492 614759989 162589250 880437100 802283478 767706251 918272040 97844949 951229529 786897750 737134131 510229873 819289986 185381858 425466253 540706260 961670448 629919942 149232855 67226103 211020871 455055945 271367185 171008168 991351226 53522333 352402529 516121044 594...
result:
ok 200000 lines
Test #9:
score: 0
Accepted
time: 242ms
memory: 44860kb
input:
200000 200000 38038021 69040924 82007527 90501435 17042028 25273916 65419739 81198606 33119526 35485232 9420557 65220276 52730771 79691383 41280910 75154865 96072226 96600873 5338675 18266601 9861697 20183305 3901227 75995924 5329268 79253609 52693141 82727193 54068199 95956893 21819711 49341282 296...
output:
7030934 211041663 62370377 419232187 968990002 518090358 946771397 680313490 732345783 860455476 610198712 853631753 516101826 3591542 728323784 659967673 309742379 270158625 909742643 310791126 750997678 572990101 564197767 28300028 291536791 986560404 161280350 946411378 332373318 746633013 813588...
result:
ok 200000 lines
Test #10:
score: 0
Accepted
time: 269ms
memory: 44876kb
input:
200000 200000 16121445 37557065 52861197 84281989 1423986 64719989 8603727 16003293 17789414 59086385 26780019 83680997 12458769 27300308 18728827 37316676 25072788 50319784 12306650 73736693 67247054 84785282 20742906 91103433 1567466 30415285 8376246 65787362 41335365 74447013 18851552 34563130 50...
output:
423771160 663645747 571915318 51293397 62092310 215460585 744070931 502809680 456997262 898200681 615306696 326299988 224129805 668084399 373001179 567479729 291163299 255288316 509561256 288660870 993268688 204832939 4459354 422983825 246541618 864905781 692401710 454728073 954835506 598048950 4726...
result:
ok 200000 lines