QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85189 | #5693. 众数 | fengyuyue | AC ✓ | 10ms | 5732kb | C++14 | 3.3kb | 2023-03-07 08:47:28 | 2023-03-07 08:47:31 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define gc getchar
#define pc putchar
#define pii pair<int,int>
#define pil pair<int,long long>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define For(i,l,r) for(int i=(l);i<=(r);i++)
#define IFor(i,r,l) for(int i=(r);i>=(l);i--)
#define for_son(u) for(int e=head[u];e;e=nxt[e])
#define eps (1e-8)
#define INF 0x3f3f3f3f
using namespace std;
char aa;
namespace ljh
{
namespace IO
{
// const int SIZ=1<<20;
// char ibuf[SIZ],*p1,*p2,obuf[SIZ],*p3=obuf;
// #define gc() (p1==p2&&(p2=(p1=ibuf)+fread(ibuf,1,SIZ,stdin),p1==p2)?EOF:*p1++)
// void pc(const char &c)
// {
// if(p3-obuf==SIZ) fwrite(obuf,1,SIZ,stdout),p3=obuf;
// *p3++=c;
// }
int rd()
{
int x=0,f=1;
char ch=gc();
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=gc();
}
while(isdigit(ch)){
x=x*10+ch-'0';
ch=gc();
}
return x*f;
}
void wr(int x,char ch)
{
if(x<0) x=-x,pc('-');
static char st[22];
int top=0;
do{
st[top++]=x%10+'0',x/=10;
}while(x);
while(top) pc(st[--top]);
pc(ch);
}
ll ll_rd()
{
ll x=0;
int f=1;
char ch=gc();
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=gc();
}
while(isdigit(ch)){
x=x*10+ch-'0';
ch=gc();
}
return x*f;
}
void ll_wr(ll x,char ch)
{
if(x<0) x=-x,pc('-');
static char st[22];
int top=0;
do{
st[top++]=x%10+'0',x/=10;
}while(x);
while(top) pc(st[--top]);
pc(ch);
}
}
using namespace IO;
const int N=1e5+5,mod=0;
namespace tem
{
// void add_edge(int u,int v){nxt[++cnt]=head[u],to[cnt]=v,head[u]=cnt;}
int qpow(int a,int b,int p)
{
a%=p;
int res=1;
while(b){
if(b&1) res=1ll*res*a%p;
a=1ll*a*a%p;
b>>=1;
}
return res;
}
int get_inv(int x){return qpow(x,mod-2,mod);}
int lowbit(int x){return x&(-x);}
void add(int &x,const int y){ x=(x+y>=mod?x+y-mod:x+y); }
// int get(int x) {return fa[x]==x?x:fa[x]=get(fa[x])};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
}
using namespace tem;
int n,a[N],s[N],f[N],ans;
void main()
{
n=rd();
IFor(i,n,1) a[i]=rd();
For(i,1,n){
int p=upper_bound(s+1,s+i,a[i])-s-1;
ans+=f[p]+(n-p)*(a[i]-s[p]);
s[i]=s[i-1],f[i]=f[i-1];
if(p+1==i) s[i]+=a[i]-s[p],f[i]+=(n-i+1)*(a[i]-s[p]);
// else s[i]=
// cerr<<n-i+1<<" "<<f[p]+(n-p)*(a[i]-s[p])<<endl;
}
ll_wr(ans,'\n');
// fwrite(obuf,1,p3-obuf,stdout);
}
/*
*/
}
char bb;
signed main()
{
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
// int st=clock();
ljh::main();
// int ed=clock();
// cerr<<ed-st<<"ms"<<endl;
// cerr<<(&bb-&aa)/1024/1024<<"MB"<<endl;
// fclose(stdin);
// fclose(stdout);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 5728kb
input:
99991 3 3 3 4 3 6 4 2 2 5 3 2 3 5 3 3 2 1 2 3 4 2 3 4 3 3 3 4 3 3 3 2 3 2 3 2 4 3 3 2 3 5 3 5 4 2 4 3 3 1 3 2 2 3 4 2 3 3 2 2 4 5 3 2 3 3 1 3 3 4 1 3 4 5 1 1 3 4 2 4 3 2 5 3 3 2 2 2 4 2 4 2 2 4 2 4 3 3 2 3 2 2 1 4 3 1 3 1 2 2 3 1 1 5 2 1 2 2 3 3 1 4 4 4 3 3 3 3 1 3 3 5 5 4 4 3 3 3 4 3 6 5 3 1 1 2 2 ...
output:
4973056284288
result:
ok single line: '4973056284288'
Test #2:
score: 0
Accepted
time: 3ms
memory: 5036kb
input:
69992 90001 89998 90001 90001 89997 90000 90000 90002 90003 90003 90001 89999 89999 90000 90000 90000 90000 90000 90000 90001 90000 89999 90002 90001 90000 89998 89998 90001 89998 90000 90000 89999 90000 90001 89998 90000 90004 90000 90000 90001 89999 90001 90003 89998 90001 90001 90001 90001 90002 ...
output:
465680822171522
result:
ok single line: '465680822171522'
Test #3:
score: 0
Accepted
time: 9ms
memory: 5220kb
input:
79992 999 1001 1000 999 997 1002 1003 1000 1002 1001 1004 1000 1000 1002 1001 1000 1002 1000 999 998 1001 998 1000 1001 1000 1001 999 1001 1000 1001 1001 1001 1000 1000 1001 1001 1002 999 1002 1000 997 999 1002 1000 999 999 999 997 1003 1002 999 1000 998 997 999 1000 1001 999 1000 1003 999 999 1001 ...
output:
2099568054432
result:
ok single line: '2099568054432'
Test #4:
score: 0
Accepted
time: 10ms
memory: 5264kb
input:
79995 99997 99999 100000 99999 99999 100000 99999 99998 99997 99999 100000 99999 99998 100000 99999 99999 100000 99999 99996 99995 99996 99996 99994 99993 99994 99995 99993 99996 99996 99995 99998 99995 99993 99993 99997 99995 99995 99996 99995 99996 99994 99994 99996 99995 99995 99997 99997 99996 9...
output:
597436378953787
result:
ok single line: '597436378953787'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3400kb
input:
2 97077 93226
output:
376755
result:
ok single line: '376755'
Test #6:
score: 0
Accepted
time: 2ms
memory: 3352kb
input:
100 90081 90225 90250 90271 90341 90362 90387 90414 90455 90500 90589 90641 90687 90691 90715 90722 90731 90866 90900 91180 91224 91256 91387 91558 91617 91632 91665 91717 92360 92806 92820 92845 92852 92853 93021 93042 93068 93156 93212 93274 93444 93537 93604 93711 93733 93836 93909 94015 94068 94...
output:
946924500
result:
ok single line: '946924500'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3340kb
input:
100 99460 98233 94497 92874 91707 91443 89387 88877 88744 87085 85679 84707 83527 82943 82121 82107 78982 78879 78241 77720 77080 76481 76068 74980 74611 74487 74450 73100 72302 72214 70826 70766 70027 69790 69384 68887 67198 66447 66029 65739 65592 64467 63711 63397 61683 59072 56810 53435 52849 52...
output:
366000017
result:
ok single line: '366000017'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
993 34 51 64 15 55 16 55 35 18 62 51 10 37 27 50 44 64 15 1 63 53 57 66 45 61 11 18 50 66 61 43 37 55 30 41 58 63 40 55 16 37 58 51 49 62 55 35 44 64 34 58 43 41 58 31 36 12 51 34 32 46 48 32 53 12 66 63 43 51 27 43 38 2 58 56 31 40 46 57 66 55 44 35 19 39 47 30 37 39 39 64 40 29 32 57 37 50 44 34 2...
output:
40454319
result:
ok single line: '40454319'
Test #9:
score: 0
Accepted
time: 2ms
memory: 4752kb
input:
60000 99999 99999 99997 99996 99996 99994 99992 99992 99988 99988 99984 99984 99983 99981 99981 99977 99977 99978 99973 99968 99965 99968 99961 99961 99961 99958 99955 99958 99956 99956 99952 99949 99952 99950 99949 99945 99944 99942 99941 99936 99937 99935 99931 99930 99930 99929 99923 99924 99922 ...
output:
119997898349058
result:
ok single line: '119997898349058'
Test #10:
score: 0
Accepted
time: 5ms
memory: 5264kb
input:
79997 11240 37280 50257 19453 44653 14897 20693 50513 5106 5099 51113 5776 69819 80837 28194 84967 53473 41380 1679 45336 6472 3140 19052 4487 83421 13168 28065 35279 94192 88836 81411 20279 48551 21414 57848 8548 77649 94678 66626 6751 1874 25359 41865 30659 37719 77881 32078 54038 38744 85200 2403...
output:
320997616259355
result:
ok single line: '320997616259355'
Test #11:
score: 0
Accepted
time: 2ms
memory: 5732kb
input:
99997 99999 99994 99998 99998 100000 99999 99995 100000 99998 100000 99997 99999 100000 100000 99998 99997 99999 99999 99996 99994 99999 99998 99997 99999 99997 100000 5665 99998 99997 99998 99996 99998 99997 99996 99998 99998 99998 99996 99998 99999 99999 99997 99998 99997 99997 99997 100000 99997 ...
output:
966704175674031
result:
ok single line: '966704175674031'
Test #12:
score: 0
Accepted
time: 6ms
memory: 4564kb
input:
49993 9115 52815 19655 4538 26673 2905 2904 30346 24500 88467 91035 2905 30342 91033 5376 19419 19656 2903 83887 91034 83890 42873 83890 42870 24502 19421 58528 9111 26675 35984 35983 9115 30346 58891 19420 88467 35982 2903 24500 35981 19660 35982 78775 4537 19420 58893 4541 24500 91034 4538 19422 2...
output:
100071885757841
result:
ok single line: '100071885757841'
Test #13:
score: 0
Accepted
time: 7ms
memory: 5724kb
input:
99991 93540 93537 93540 93540 93539 93540 93541 93538 93540 93538 93541 93539 93541 93537 93540 93540 93540 93540 93540 93540 93538 93541 93540 93540 93537 93540 93541 93540 93542 93540 93537 93542 93541 93541 93540 93540 93538 93539 93540 93538 93540 93537 93542 93539 93544 93541 93544 93540 93542 ...
output:
272602857817651
result:
ok single line: '272602857817651'