QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#867024 | #9792. Ogre Sort | jimmyywang | TL | 1614ms | 11852kb | C++23 | 2.2kb | 2025-01-23 00:34:21 | 2025-01-23 00:34:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll int
#define f(i,a,b) for(ll i=a;i<=b;i++)
#define wt int tt=d;while(tt--)
#define py puts("Yes")
#define pn puts("No")
#define fe(i,e) for(int i=0;i<e.size();i++)
#define vi vector<ll>
inline ll rd() {
ll x=0,f=1;
char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c))x=x*10+c-'0',c=getchar();
return x*f;
}
namespace binom{
const ll Lim=300010,mod=998244353;
ll jc[Lim],inv[Lim],inc[Lim];
void pre(){
jc[0]=jc[1]=inc[0]=inc[1]=inv[0]=inv[1]=1;
f(i,2,Lim-1)jc[i]=jc[i-1]*i%mod,inv[i]=(mod-mod/i)*inv[mod%i]%mod,
inc[i]=inc[i-1]*inv[i]%mod;
}ll C(ll n,ll m){if(n<0||m<0||n<m)return 0;return jc[n]*inc[m]%mod*inc[n-m]%mod;}
}
// using namespace binom;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
#define d rd()
#define pb push_back
const ll N=300010;
struct edge{ll v,w,nx;}e[N<<1];
ll hd[N],cnt;
void add(ll u,ll v,ll w){e[++cnt]=(edge){v,w,hd[u]};hd[u]=cnt;}
ll qp(ll a,ll b,ll p){
ll ans=1;while(b){
if(b&1)ans=ans*a%p;
a=a*a%p;b>>=1;
}return ans;
}ll n,m;
ll a[300010];
ll t[600010<<2];
#define ls(p) (p<<1)
#define rs(p) (p<<1|1)
void upd(ll p){
t[p]=(t[ls(p)]+t[rs(p)]);
}void build(ll l,ll r,ll p){
if(l==r){t[p]=(l>n);return;}
ll mid=l+r>>1;
build(l,mid,ls(p));
build(mid+1,r,rs(p));
upd(p);
}void add(ll l,ll r,ll p,ll pos,ll v){
if(l==r){t[p]+=v;return;}
ll mid=l+r>>1;
if(mid>=pos)add(l,mid,ls(p),pos,v);
else add(mid+1,r,rs(p),pos,v);
upd(p);
}ll ask(ll l,ll r,ll p,ll L,ll R){
if(l==r)return t[p];
ll mid=l+r>>1,res=0;
if(mid>=L)res+=ask(l,mid,ls(p),L,R);
if(mid<R)res+=ask(mid+1,r,rs(p),L,R);
return res;
}ll pos[300010];
ll res,x[300010],y[300010];
int main(){
n=d;f(i,1,n)a[i]=d,pos[a[i]]=i;
build(1,2*n,1);
ll P=pos[n];
for(int i=n-1;i>=1;i--){
if(pos[i]<P){P=pos[i];continue;}
else {
if(P>0)P=0;else P--;
x[++res]=ask(1,2*n,1,1,pos[i]+n);
y[res]=1;
add(1,2*n,1,pos[i]+n,-1);
add(1,2*n,1,P+n,1);
}
}
cout<<res<<" "<<res<<endl;
f(i,1,res)cout<<x[i]<<" "<<y[i]<<endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 7752kb
input:
4 1 2 4 3
output:
3 3 4 1 3 1 3 1
result:
ok Participant's output is correct
Test #2:
score: 0
Accepted
time: 1ms
memory: 11852kb
input:
5 2 4 1 3 5
output:
3 3 4 1 2 1 4 1
result:
ok Participant's output is correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 9804kb
input:
3 1 2 3
output:
0 0
result:
ok Participant's output is correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 7760kb
input:
4 1 2 4 3
output:
3 3 4 1 3 1 3 1
result:
ok Participant's output is correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 11836kb
input:
5 2 4 1 3 5
output:
3 3 4 1 2 1 4 1
result:
ok Participant's output is correct
Test #6:
score: 0
Accepted
time: 0ms
memory: 7752kb
input:
3 1 2 3
output:
0 0
result:
ok Participant's output is correct
Test #7:
score: 0
Accepted
time: 0ms
memory: 11848kb
input:
1 1
output:
0 0
result:
ok Participant's output is correct
Test #8:
score: 0
Accepted
time: 1ms
memory: 11852kb
input:
5 5 3 4 1 2
output:
4 4 3 1 3 1 5 1 5 1
result:
ok Participant's output is correct
Test #9:
score: 0
Accepted
time: 0ms
memory: 9804kb
input:
5 4 1 2 3 5
output:
3 3 4 1 4 1 4 1
result:
ok Participant's output is correct
Test #10:
score: 0
Accepted
time: 0ms
memory: 11852kb
input:
5 1 3 4 2 5
output:
2 2 4 1 2 1
result:
ok Participant's output is correct
Test #11:
score: 0
Accepted
time: 0ms
memory: 9804kb
input:
5 1 4 5 2 3
output:
3 3 5 1 5 1 3 1
result:
ok Participant's output is correct
Test #12:
score: 0
Accepted
time: 1ms
memory: 9800kb
input:
5 1 5 4 3 2
output:
4 4 3 1 4 1 5 1 4 1
result:
ok Participant's output is correct
Test #13:
score: 0
Accepted
time: 1ms
memory: 11852kb
input:
5 3 2 1 5 4
output:
4 4 5 1 2 1 3 1 4 1
result:
ok Participant's output is correct
Test #14:
score: 0
Accepted
time: 0ms
memory: 9804kb
input:
5 2 5 3 1 4
output:
4 4 5 1 4 1 3 1 5 1
result:
ok Participant's output is correct
Test #15:
score: 0
Accepted
time: 0ms
memory: 11848kb
input:
5 2 1 4 5 3
output:
3 3 5 1 2 1 3 1
result:
ok Participant's output is correct
Test #16:
score: 0
Accepted
time: 0ms
memory: 11852kb
input:
5 5 3 2 1 4
output:
4 4 5 1 3 1 4 1 5 1
result:
ok Participant's output is correct
Test #17:
score: 0
Accepted
time: 0ms
memory: 7760kb
input:
5 5 3 1 4 2
output:
4 4 4 1 3 1 5 1 5 1
result:
ok Participant's output is correct
Test #18:
score: 0
Accepted
time: 0ms
memory: 9600kb
input:
5 3 1 5 4 2
output:
4 4 4 1 2 1 5 1 4 1
result:
ok Participant's output is correct
Test #19:
score: 0
Accepted
time: 0ms
memory: 11852kb
input:
5 1 4 5 3 2
output:
3 3 4 1 5 1 3 1
result:
ok Participant's output is correct
Test #20:
score: 0
Accepted
time: 0ms
memory: 11848kb
input:
5 1 4 3 2 5
output:
3 3 3 1 4 1 3 1
result:
ok Participant's output is correct
Test #21:
score: 0
Accepted
time: 0ms
memory: 11852kb
input:
5 1 4 3 5 2
output:
3 3 3 1 5 1 3 1
result:
ok Participant's output is correct
Test #22:
score: 0
Accepted
time: 0ms
memory: 9800kb
input:
5 3 5 4 2 1
output:
4 4 3 1 2 1 4 1 5 1
result:
ok Participant's output is correct
Test #23:
score: 0
Accepted
time: 0ms
memory: 7752kb
input:
5 1 5 4 2 3
output:
4 4 3 1 5 1 5 1 4 1
result:
ok Participant's output is correct
Test #24:
score: 0
Accepted
time: 0ms
memory: 7756kb
input:
5 2 4 5 3 1
output:
3 3 4 1 2 1 5 1
result:
ok Participant's output is correct
Test #25:
score: 0
Accepted
time: 0ms
memory: 9808kb
input:
5 1 3 2 4 5
output:
2 2 3 1 2 1
result:
ok Participant's output is correct
Test #26:
score: 0
Accepted
time: 1ms
memory: 9804kb
input:
5 1 5 3 2 4
output:
4 4 5 1 4 1 5 1 4 1
result:
ok Participant's output is correct
Test #27:
score: 0
Accepted
time: 0ms
memory: 9804kb
input:
5 2 1 3 5 4
output:
4 4 5 1 4 1 3 1 4 1
result:
ok Participant's output is correct
Test #28:
score: 0
Accepted
time: 0ms
memory: 9804kb
input:
5 1 3 5 2 4
output:
4 4 5 1 3 1 5 1 4 1
result:
ok Participant's output is correct
Test #29:
score: 0
Accepted
time: 0ms
memory: 11852kb
input:
5 5 1 4 2 3
output:
4 4 3 1 5 1 5 1 5 1
result:
ok Participant's output is correct
Test #30:
score: 0
Accepted
time: 0ms
memory: 9800kb
input:
5 2 5 3 4 1
output:
4 4 4 1 4 1 3 1 5 1
result:
ok Participant's output is correct
Test #31:
score: 0
Accepted
time: 0ms
memory: 11852kb
input:
5 3 4 1 2 5
output:
2 2 4 1 4 1
result:
ok Participant's output is correct
Test #32:
score: 0
Accepted
time: 1ms
memory: 11852kb
input:
20 11 2 3 1 6 12 13 5 14 4 8 15 16 7 17 9 10 18 19 20
output:
10 10 17 1 17 1 13 1 16 1 9 1 12 1 14 1 10 1 10 1 11 1
result:
ok Participant's output is correct
Test #33:
score: 0
Accepted
time: 0ms
memory: 7756kb
input:
20 4 3 1 6 7 5 8 9 10 11 2 12 13 14 15 16 17 18 19 20
output:
5 5 6 1 2 1 3 1 11 1 5 1
result:
ok Participant's output is correct
Test #34:
score: 0
Accepted
time: 0ms
memory: 9804kb
input:
200 4 61 13 19 62 63 10 3 2 23 64 65 66 49 15 34 67 68 69 70 71 24 72 30 7 73 74 75 20 76 77 78 37 79 47 80 81 82 33 31 57 51 83 60 28 84 36 85 54 53 86 87 42 41 40 9 50 59 88 89 90 56 91 45 92 58 93 94 95 96 16 97 98 29 99 100 44 101 8 27 102 103 32 104 105 25 21 17 52 106 11 107 6 22 38 108 109 14...
output:
60 60 44 1 58 1 66 1 44 1 63 1 106 1 53 1 54 1 90 1 50 1 62 1 25 1 112 1 47 1 107 1 69 1 81 1 106 1 64 1 65 1 66 1 108 1 100 1 55 1 65 1 112 1 41 1 62 1 91 1 64 1 52 1 84 1 67 1 89 1 113 1 95 1 56 1 47 1 102 1 97 1 64 1 45 1 130 1 99 1 89 1 57 1 106 1 50 1 126 1 103 1 55 1 83 1 98 1 69 1 105 1 112 1...
result:
ok Participant's output is correct
Test #35:
score: 0
Accepted
time: 0ms
memory: 9800kb
input:
200 24 25 11 5 4 12 9 26 27 7 28 29 3 30 14 17 15 20 18 31 6 32 33 22 8 34 35 21 16 19 36 37 2 10 38 23 39 13 40 41 1 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...
output:
23 23 36 1 25 1 29 1 21 1 31 1 23 1 22 1 31 1 24 1 24 1 38 1 17 1 15 1 36 1 19 1 31 1 23 1 29 1 21 1 22 1 27 1 36 1 41 1
result:
ok Participant's output is correct
Test #36:
score: 0
Accepted
time: 15ms
memory: 9800kb
input:
2000 1741 1583 1742 244 90 1743 1744 1745 1428 1746 1747 50 1537 1748 749 1749 1067 622 1750 1751 1752 1753 1754 1755 1547 1756 1757 1663 1758 403 1759 1760 1761 1762 1677 1763 1764 1030 1280 1765 1717 939 1766 711 1767 1768 1769 1770 1055 1771 1772 1061 1773 1214 1716 1774 1775 1144 1776 1777 1778 ...
output:
1740 1740 1926 1 1053 1 935 1 1743 1 1429 1 1802 1 770 1 1039 1 559 1 1745 1 1576 1 1875 1 582 1 1308 1 1439 1 1158 1 1558 1 1933 1 1412 1 1373 1 1932 1 1177 1 1406 1 64 1 78 1 1887 1 1258 1 1922 1 1095 1 541 1 1288 1 1789 1 561 1 1462 1 1531 1 1421 1 1469 1 1192 1 742 1 1027 1 860 1 139 1 1620 1 18...
result:
ok Participant's output is correct
Test #37:
score: 0
Accepted
time: 7ms
memory: 9804kb
input:
2000 985 926 580 986 645 623 987 988 816 989 990 991 50 992 437 993 541 994 800 995 996 997 998 28 999 34 110 57 611 1000 724 97 662 1001 1002 1003 351 1004 280 1005 1006 936 181 148 1007 109 1008 549 1009 1010 714 1011 1012 1013 1014 192 1015 67 1016 783 1017 1018 1019 944 402 722 1020 1021 903 671...
output:
984 984 1390 1 325 1 1391 1 890 1 1117 1 922 1 407 1 523 1 169 1 1662 1 1503 1 1475 1 555 1 1473 1 512 1 106 1 1521 1 825 1 1421 1 930 1 368 1 1366 1 438 1 1086 1 1859 1 1825 1 623 1 1396 1 1677 1 537 1 1759 1 1101 1 1096 1 943 1 1068 1 970 1 1070 1 205 1 1244 1 1516 1 104 1 766 1 1473 1 1627 1 760 ...
result:
ok Participant's output is correct
Test #38:
score: 0
Accepted
time: 1614ms
memory: 11684kb
input:
19934 19839 19840 13621 19841 271 19842 4329 19843 19844 17253 8288 19845 5182 19846 11341 8790 7371 19847 19848 19849 19850 17841 3277 19851 19852 19853 19854 19855 17960 19856 10580 19857 730 7813 19858 371 11760 19859 19860 17938 19861 4585 19862 12350 19863 15426 19864 19865 19866 14628 11864 19...
output:
19838 19838 18815 1 1612 1 628 1 17941 1 11483 1 1243 1 2174 1 15019 1 14382 1 3175 1 3235 1 16224 1 12739 1 15661 1 18995 1 3263 1 17294 1 7080 1 17541 1 15441 1 18562 1 12590 1 8521 1 3259 1 9403 1 13419 1 7907 1 1060 1 13293 1 12707 1 7663 1 13747 1 3043 1 4250 1 5141 1 4083 1 19277 1 18705 1 863...
result:
ok Participant's output is correct
Test #39:
score: 0
Accepted
time: 1284ms
memory: 11852kb
input:
19934 5219 14820 14821 14822 14823 14824 14825 3510 14826 14827 14828 2256 4166 14829 14830 14788 8570 5618 14831 14832 13392 14833 10688 4209 14834 14835 12575 14836 8996 12088 7132 2554 14837 14220 14838 11060 796 14839 5982 14840 1775 14841 3247 14842 12204 14843 9493 8928 6087 14844 1831 12138 1...
output:
14819 14819 4260 1 10037 1 17234 1 8096 1 17680 1 5550 1 14954 1 14388 1 8800 1 12455 1 13926 1 159 1 10932 1 1982 1 5217 1 12410 1 11199 1 6911 1 1875 1 5987 1 15954 1 13912 1 18716 1 17168 1 10729 1 12456 1 7180 1 17378 1 16446 1 5384 1 268 1 47 1 14767 1 11268 1 5006 1 13611 1 11749 1 12929 1 388...
result:
ok Participant's output is correct
Test #40:
score: 0
Accepted
time: 0ms
memory: 11688kb
input:
5 4 5 2 1 3
output:
3 3 5 1 4 1 5 1
result:
ok Participant's output is correct
Test #41:
score: -100
Time Limit Exceeded
input:
90000 65253 42375 65254 38419 27902 4421 65255 65256 43571 8888 65257 65258 65259 56046 48333 65260 41674 28086 17472 60606 57320 45775 30789 65261 65262 65263 65264 65265 58837 65266 6340 65267 65268 65269 49935 65270 65271 2758 24781 53306 26100 65272 65273 56411 65274 65275 54501 53036 53922 3988...