QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#469116 | #8732. Zečevi | honglan0301 | 9 | 7146ms | 235592kb | C++17 | 6.8kb | 2024-07-09 14:36:23 | 2024-07-09 14:36:23 |
Judging History
answer
/*
author: honglan0301
Sexy_goodier _ xiaoqing
*/
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cctype>
#include <queue>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <bitset>
#include <assert.h>
using namespace std;
//namespace Fread{const int SIZE=1<<20;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return*S++;}}using namespace Fread;namespace Fwrite{const int SIZE=1<<20;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}using namespace Fwrite;
//#define getchar Fread::getchar
//#define putchar Fwrite::putchar
namespace Fastio{struct Reader{template<typename T>Reader&operator>>(T&x){x=0;short f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();x*=f;return*this;}Reader&operator>>(double&x){x=0;double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(long double&x){x=0;long double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(__float128&x){x=0;__float128 t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(char&c){c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();return*this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(string&str){str.clear();char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{const int Setprecision=6;typedef int mxdouble;template<typename T>Writer&operator<<(T x){if(x==0){putchar('0');return*this;}if(x<0)putchar('-'),x=-x;static short sta[40];short top=0;while(x>0)sta[++top]=x%10,x/=10;while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(long double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(long double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(__float128 x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(__float128)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(char c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}using namespace Fastio;
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl//;fflush(stdout)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long
#define ll long long
#define ull unsigned long long
#define mod 998244353
#define G 3
#define Gi 332748118
mt19937 rnd(time(0));
mt19937_64 rndl(time(0));
int n,m,flag,lim=3000000000000000000ll;
pair<int,int> x[100005],y[100005];
struct tree
{
int ls,rs,tag,len; ll sum;
}tree[10000005];
int cntd,rt;
#define ls(x) tree[x].ls
#define rs(x) tree[x].rs
#define l(x) tree[x].len
#define n(x) tree[x].sum
#define tg(x) tree[x].tag
#define md(x,y) ((x+y)>>1)
#define push_up(x) l(x)=l(ls(x))+l(rs(x)),n(x)=n(ls(x))+n(rs(x))
#define cz(k,p) tg(p)+=k,n(p)+=1ll*k*l(p)
void push_down(int p)
{
if(tg(p))
{
if(!ls(p)) ls(p)=++cntd,l(ls(p))=(l(p)+1)/2; cz(tg(p),ls(p));
if(!rs(p)) rs(p)=++cntd,l(rs(p))=l(p)/2; cz(tg(p),rs(p)); tg(p)=0;
}
}
void cza(int l,int r,int x,int y,int k,int &p)
{
if(!p) p=++cntd,l(p)=r-l+1; if(l>=x&&r<=y) return cz(k,p),void(); int mid=md(l,r); push_down(p);
if(mid>=x) cza(l,mid,x,y,k,ls(p)); if(mid<y) cza(mid+1,r,x,y,k,rs(p)); push_up(p);
}
void czf(int l,int r,int k,int p)
{
if(l==r) return n(p)-=k,void(); int mid=md(l,r); push_down(p);
if(n(ls(p))<=k) czf(mid+1,r,k-n(ls(p)),rs(p)),ls(p)=0; else czf(l,mid,k,ls(p)); push_up(p);
}
int askm(int l,int r,int p)
{
if(l==r) return l; int mid=md(l,r); push_down(p);
if(n(ls(p))) return askm(l,mid,ls(p)); else return askm(mid+1,r,rs(p));
}
void ins(pair<int,int> xx,int k)
{
if(xx.se>=k) return;
cza(0,lim,xx.fi+xx.se,xx.fi+k-1,1,rt);
}
void del(pair<int,int> xx,int k)
{
flag&=askm(0,lim,rt)>=xx.fi;
if(n(rt)<=xx.se) rt=0; else czf(0,lim,xx.se,rt);
}
void clr()
{
for(int i=1;i<=cntd;i++) ls(i)=rs(i)=n(i)=tg(i)=l(i)=0; cntd=rt=0;
}
int ck(int k)
{
int nzl=1,nzr=1; flag=1;
while(nzl<=n&&nzr<=m)
{
if(x[nzl].fi<y[nzr].fi) ins(x[nzl++],k);
else del(y[nzr++],k);
}
while(nzl<=n) ins(x[nzl++],k);
while(nzr<=m) del(y[nzr++],k);
flag&=askm(0,lim,rt)==lim; clr(); return flag;
}
signed main()
{
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>x[i].fi>>x[i].se;
for(int i=1;i<=m;i++) cin>>y[i].fi>>y[i].se;
sort(x+1,x+n+1); sort(y+1,y+m+1);
int l=0,r=0;
for(int i=1;i<=n;i++) r+=x[i].se;
for(int i=1;i<=m;i++) r+=y[i].se; r/=n;
while(l<=r)
{
int mid=(l+r)>>1;
if(ck(mid)) l=mid+1; else r=mid-1;
}
cout<<r<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 9
Accepted
Test #1:
score: 9
Accepted
time: 6877ms
memory: 230524kb
input:
1 100000 25117044 970963458 373893849 968275175 426927003 756404237 402749243 884153855 655982073 231540010 925839527 380078009 580079136 593952762 505135862 82095067 52931312 190936477 921699044 178656266 22689680 495676031 439196655 96470058 508403382 453576184 728333782 206229498 227588452 887461...
output:
48772599075036
result:
ok 1 number(s): "48772599075036"
Test #2:
score: 0
Accepted
time: 7146ms
memory: 235592kb
input:
1 100000 2033786 701332275 425793984 100641701 791989716 91816064 729205086 630057419 128219506 625052640 946256338 430845673 49961714 406789641 320023538 493235898 124624293 153525734 12609738 732965886 164381879 595730434 870380571 604015896 817352253 354163189 543418085 277237438 517916847 853100...
output:
49887362883766
result:
ok 1 number(s): "49887362883766"
Test #3:
score: 0
Accepted
time: 6945ms
memory: 228196kb
input:
1 100000 42752820 122926409 10513202 836122032 810112260 169484171 599386731 844238794 981228176 849710441 374165341 461389522 225540019 875636296 980026848 262331868 968727347 672445689 891073264 161158988 646651074 368927855 120467285 916656970 480861097 457383460 656857845 965285555 862807432 941...
output:
47874399443765
result:
ok 1 number(s): "47874399443765"
Test #4:
score: 0
Accepted
time: 6815ms
memory: 225704kb
input:
1 100000 45772116 978871680 436898166 365158248 732294552 488461892 109283264 904017928 481282469 365782765 149950749 558650411 637756555 761954186 441342826 245462952 837682335 825241583 231785990 856221029 865481036 890572033 713521646 284438736 937611078 690679712 48500295 268860937 701774950 907...
output:
47794145143247
result:
ok 1 number(s): "47794145143247"
Test #5:
score: 0
Accepted
time: 6730ms
memory: 223856kb
input:
1 100000 54417600 455585786 185157112 23259714 235040467 851577574 357897786 945899735 100775093 679820579 205023325 988165434 825564014 253769836 202188435 59892940 337396895 514922202 658461608 769509576 241359680 886440279 258711817 564489459 565017776 549386805 901984139 145266237 3641050 935060...
output:
47119066086794
result:
ok 1 number(s): "47119066086794"
Test #6:
score: 0
Accepted
time: 3527ms
memory: 105964kb
input:
1 100000 71480876 782458735 418412356 4433 418416789 7359 418424148 3577 418427725 6204 418433929 2537 418436466 6358 418442824 4124 418446948 2713 418449661 6258 418455919 6637 418462556 2331 418464887 2262 418467149 2504 418469653 3744 418473397 688 418474085 4975 418479060 2061 418481121 5928 418...
output:
1608752150
result:
ok 1 number(s): "1608752150"
Test #7:
score: 0
Accepted
time: 3561ms
memory: 103076kb
input:
1 100000 70736826 689941541 202494343 3048 202497391 2446 202499837 6318 202506155 303 202506458 5886 202512344 4048 202516392 4537 202520929 427 202521356 1944 202523300 2478 202525778 5925 202531703 1224 202532927 224 202533151 5051 202538202 6119 202544321 836 202545157 5106 202550263 3864 202554...
output:
1592473193
result:
ok 1 number(s): "1592473193"
Test #8:
score: 0
Accepted
time: 3526ms
memory: 104936kb
input:
1 100000 90679177 731208489 444799446 7049 444806495 5992 444812487 656 444813143 2762 444815905 3073 444818978 257 444819235 6057 444825292 5667 444830959 6211 444837170 450 444837620 5923 444843543 7081 444850624 2076 444852700 2823 444855523 5443 444860966 2184 444863150 6344 444869494 2041 44487...
output:
1474188594
result:
ok 1 number(s): "1474188594"
Test #9:
score: 0
Accepted
time: 3563ms
memory: 105872kb
input:
1 100000 99481748 781962846 427794638 4239 427798877 5115 427803992 4376 427808368 5084 427813452 6302 427819754 7063 427826817 6196 427833013 6369 427839382 4255 427843637 2647 427846284 4303 427850587 7261 427857848 2929 427860777 1817 427862594 7754 427870348 5113 427875461 621 427876082 3819 427...
output:
1625835386
result:
ok 1 number(s): "1625835386"
Test #10:
score: 0
Accepted
time: 3153ms
memory: 89336kb
input:
1 100000 16521427 168641806 48125403 944 48126347 1560 48127907 83 48127990 85 48128075 1008 48129083 922 48130005 438 48130443 1454 48131897 1056 48132953 492 48133445 1347 48134792 689 48135481 156 48135637 515 48136152 1665 48137817 58 48137875 732 48138607 567 48139174 687 48139861 1072 48140933...
output:
389963535
result:
ok 1 number(s): "389963535"
Subtask #2:
score: 0
Wrong Answer
Test #11:
score: 12
Accepted
time: 97ms
memory: 55428kb
input:
100000 1 866301171 366511673 782130035 523593023 210159324 951803750 33819604 974027339 517904111 963671594 281974787 391051697 568097534 965085338 81004963 640086904 211218893 397278600 614725688 4366212 269152510 559992280 327491679 276555612 630131521 503842459 15556017 382637565 444080049 985512...
output:
1745
result:
ok 1 number(s): "1745"
Test #12:
score: 0
Accepted
time: 99ms
memory: 53356kb
input:
100000 1 602052974 747930871 526492952 570148581 533976658 194147542 178657958 99194566 225173261 577928477 516902495 724134685 601150433 924258430 567498378 534418876 488767427 577178596 272110248 850482707 76905239 32663753 295653369 667089720 95647198 469443114 260333259 658091403 516052242 82742...
output:
3011
result:
ok 1 number(s): "3011"
Test #13:
score: 0
Accepted
time: 83ms
memory: 55340kb
input:
100000 1 62539585 679422422 292493838 651257494 18409931 47903905 667787194 128774888 124839461 365507846 23418045 612484173 406280354 862649934 843234438 905245338 400001312 225717248 755168314 822417263 515758415 201237721 556110002 980912248 173338563 53323238 246379086 756633035 337266161 257609...
output:
1262
result:
ok 1 number(s): "1262"
Test #14:
score: 0
Accepted
time: 101ms
memory: 53292kb
input:
100000 1 574489065 743770763 211882181 288604464 129739889 284534337 331811875 391318315 37416063 608986445 534902036 696548051 268694357 19640591 239365234 576914400 10623890 81786245 557001779 226639658 154345580 731344529 250688026 757559211 25475054 357657388 584637384 652051354 153156878 784586...
output:
7737
result:
ok 1 number(s): "7737"
Test #15:
score: 0
Accepted
time: 97ms
memory: 53156kb
input:
100000 1 535171471 336381440 141773641 673998275 492414591 465321245 292245188 492728685 115925345 510014389 387848714 3853854 550043834 398983084 532785924 732477862 22347128 820766474 426048009 610755195 197776236 641908217 206935657 783564876 125621396 231399245 28736236 409897555 87143269 612743...
output:
9005
result:
ok 1 number(s): "9005"
Test #16:
score: 0
Accepted
time: 73ms
memory: 36976kb
input:
100000 1 933067308 728899586 933067307 281511775 933067306 46479519 933067305 629603498 933067304 513745053 933067303 195448498 933067302 839934969 933067301 749764127 933067300 177662462 933067299 311185829 933067298 67933481 933067297 103347335 933067296 298703387 933067295 868453813 933067294 616...
output:
3899
result:
ok 1 number(s): "3899"
Test #17:
score: 0
Accepted
time: 88ms
memory: 35012kb
input:
100000 1 506382737 329612248 506382736 801627680 506382735 316738091 506382734 681410533 506382733 529449205 506382732 827584154 506382731 317177712 506382730 926503010 506382729 684230820 506382728 480953186 506382727 731683737 506382726 145817323 506382725 360514181 506382724 698908723 506382723 7...
output:
2895
result:
ok 1 number(s): "2895"
Test #18:
score: 0
Accepted
time: 74ms
memory: 34820kb
input:
100000 1 877792105 98377575 877792104 179182144 877792103 161948562 877792102 152474351 877792101 542583167 877792100 142774416 877792099 396779746 877792098 957503478 877792097 669500037 877792096 969281133 877792095 565566533 877792094 425097559 877792093 174648328 877792092 18084987 877792091 422...
output:
5070
result:
ok 1 number(s): "5070"
Test #19:
score: 0
Accepted
time: 84ms
memory: 34800kb
input:
100000 1 825085252 529127478 825085251 396026798 825085250 24693573 825085249 545809975 825085248 194420230 825085247 543957886 825085246 650476290 825085245 405647119 825085244 306150957 825085243 371524357 825085242 376087124 825085241 235930314 825085240 549879890 825085239 570607548 825085238 25...
output:
6544
result:
ok 1 number(s): "6544"
Test #20:
score: 0
Accepted
time: 86ms
memory: 34948kb
input:
100000 1 977073650 470745336 977073649 122977908 977073648 753047720 977073647 251904203 977073646 121800701 977073645 280875129 977073644 144615133 977073643 144968752 977073642 697554749 977073641 39082506 977073640 764169759 977073639 729466800 977073638 405829723 977073637 945950833 977073636 45...
output:
28463
result:
ok 1 number(s): "28463"
Test #21:
score: -12
Wrong Answer
time: 814ms
memory: 12332kb
input:
100000 1 975215810 6 975215809 9 975215808 6 975215807 12 975215806 10 975215805 9 975215804 15 975215803 15 975215802 12 975215801 20 975215800 12 975215799 22 975215798 19 975215797 20 975215796 23 975215795 25 975215794 19 975215793 27 975215792 29 975215791 30 975215790 22 975215789 30 975215788...
output:
59689
result:
wrong answer 1st numbers differ - expected: '44014', found: '59689'
Subtask #3:
score: 0
Wrong Answer
Test #26:
score: 26
Accepted
time: 6ms
memory: 6804kb
input:
1000 1000 98203901 1327928 90291962 1715530 73190581 1953419 30626944 1111081 19861765 1648083 378531325 1847131 32338803 1135925 213019894 1754207 104073495 1236818 153162191 1775836 283503659 1577207 370480039 1457117 11989599 1688477 8779089 1115475 25334382 1551917 102065341 1825040 154967698 15...
output:
1011589
result:
ok 1 number(s): "1011589"
Test #27:
score: 0
Accepted
time: 4ms
memory: 6204kb
input:
330 990 373134326 4 701492560 7 746268679 7 776119421 4 895522381 4 746268655 4 805970167 4 373134330 4 716417911 8 761194024 4 626865671 4 328358235 7 14925402 7 597014925 4 582089554 8 44776126 8 104477612 4 298507489 7 835820889 4 895522405 4 656716413 4 552238806 4 313432840 8 447761191 4 298507...
output:
9
result:
ok 1 number(s): "9"
Test #28:
score: 0
Accepted
time: 4ms
memory: 8460kb
input:
330 990 611940298 4 373134344 6 313432864 4 149253747 5 343283602 6 253731346 4 238805985 5 970149264 6 89552243 4 746268681 4 492537314 4 611940310 5 238805999 4 865671657 6 970149250 4 149253761 4 626865697 4 298507491 4 343283596 5 835820905 5 761194028 4 29850769 6 44776150 4 880597026 6 6716418...
output:
9
result:
ok 1 number(s): "9"
Test #29:
score: -26
Wrong Answer
time: 36ms
memory: 12024kb
input:
1000 1000 301268447 148470946 936559118 141508823 785790166 540015242 578859667 224889871 176466061 637491413 9490489 998352121 455152479 666386577 37725832 51483679 602037964 235495591 226213567 578127892 790576859 566555039 970586916 330226797 596431819 80912449 343462089 902326659 424623122 64254...
output:
498055454
result:
wrong answer 1st numbers differ - expected: '497728657', found: '498055454'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%