QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#786325 | #9663. Reverse Pairs Coloring | N_z_ | WA | 12ms | 5552kb | C++23 | 7.4kb | 2024-11-26 21:06:42 | 2024-11-26 21:06:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct time_helper{
#ifdef LOCAL
clock_t time_last;time_helper(){time_last=clock();}void test(){auto time_now=clock();std::cerr<<"time:"<<1.*(time_now-time_last)/CLOCKS_PER_SEC<<";all_time:"<<1.*time_now/CLOCKS_PER_SEC<<std::endl;time_last=time_now;}~time_helper(){test();}
#else
void test(){}
#endif
}time_helper;
#ifdef LOCAL
#include"dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif
namespace Fread{const int SIZE=1<<16;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++;}}namespace Fwrite{const int SIZE=1<<16;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;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
int print_precision=10;bool print_T_endl=1;char print_between=' ';
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader;struct Writer;template<size_t id>struct read_tuple{template<typename...T>static void read(Reader&stream,std::tuple<T...>&x){read_tuple<id-1>::read(stream,x);stream>>get<id-1>(x);}};template<>struct read_tuple<0>{template<typename...T>static void read([[maybe_unused]]Reader&stream,[[maybe_unused]]std::tuple<T...>&x){}};template<size_t id>struct print_tuple{template<typename...T>static void print(Writer&stream,const std::tuple<T...>&x){print_tuple<id-1>::print(stream,x);putchar(print_between);stream<<get<id-1>(x);}};template<>struct print_tuple<1>{template<typename...T>static void print(Writer&stream,const std::tuple<T...>&x){stream<<get<0>(x);}};template<>struct print_tuple<0>{template<typename...T>static void print([[maybe_unused]]Writer&stream,[[maybe_unused]]const std::tuple<T...>&x){}};
struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename...T>Reader&operator>>(std::tuple<T...>&x){read_tuple<sizeof...(T)>::read(*this,x);return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;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 return x*=f,*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;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}template<typename T1,typename T2>Reader&operator>>(std::pair<T1,T2>&x){*this>>x.first>>x.second;return *this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';
struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(const T&x){for(auto q:x){*this<<q;if(!is_class<decltype(q)>::value)*this<<print_between;}if(!is_class<typename T::value_type>::value&&print_T_endl)*this<<'\n';return *this;}template<typename...T>Writer&operator<<(const std::tuple<T...>&x){print_tuple<sizeof...(T)>::print(*this,x);if(print_T_endl)*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;x+=pow(10,-print_precision)/2;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<print_precision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<print_precision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(const T&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;}template<typename T1,typename T2>Writer&operator<<(const std::pair<T1,T2>&x){*this<<x.first<<print_between<<x.second;if(print_T_endl)*this<<'\n';return *this;}Writer&operator<<(const std::string&str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
template<class Fun>class y_combinator_result{Fun fun_;public:template<class T>explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}template<class ...Args>decltype(auto) operator()(Args &&...args){return fun_(std::ref(*this), std::forward<Args>(args)...);}};template<class Fun>decltype(auto) y_combinator(Fun &&fun){return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));}
void init();void solve(int tc);
main()
{
init();int t=1;
// cin>>t;
for(int tc=1;tc<=t;tc++)solve(tc);
}
void init()
{
}
template<int ...ns>struct BIT;
template<int U,int ...ns>
struct BIT<U,ns...>
{
BIT<ns...> BITT[U+10];
void clear(){for(int x=0;x<U+10;x++)BITT[x].clear();}
BIT(){clear();}
template<typename T1,typename ...Tn>
void add(const T1& n,const Tn& ...tn){for(int x=n+3;x<=U+5;x+=x&-x)BITT[x].add(tn...);}
template<typename T1,typename ...Tn>
int query(const T1& n,const Tn& ...tn){int r=0;for(int x=n+3;x;x-=x&-x)r+=BITT[x].query(tn...);return r;}
template<typename T1,typename T2,typename ...Tn>
int querylr(const T1& L,const T2& R,const Tn& ...tn){int r=0;for(int x=R+3;x;x-=x&-x)r+=BITT[x].querylr(tn...);for(int x=L+2;x;x-=x&-x)r-=BITT[x].querylr(tn...);return r;}
};
template<>
struct BIT<>
{
int val;
void clear(){val=0;}
BIT(){clear();}
void add(int u){val+=u;}
int query(){return val;}
int querylr(){return val;}
};
BIT<300001>t;
void solve([[maybe_unused]]int tc)
{
int n;
cin>>n;
int ans=0,lst=n+1;
vector<int>vis(n+2);
vis[n+1]=1;
for(int x=1;x<=n;x++)
{
int a;
cin>>a;
a=n+1-a;
if(a+1<=lst)ans+=(!vis[a+1])+t.querylr(a+1,lst);
if(vis[a-1])t.add(a,-1);
vis[a]=1;
if(!vis[a+1])t.add(a+1,1);
lst=a;
// cout<<ans<<endl;
}
cout<<ans<<endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 4956kb
input:
9 5 9 1 8 2 6 4 7 3
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 1ms
memory: 4920kb
input:
2 1 2
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 4764kb
input:
2 2 1
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 1ms
memory: 4796kb
input:
12 12 11 10 9 8 7 6 5 4 3 2 1
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 1ms
memory: 4688kb
input:
12 2 5 3 7 1 12 11 9 8 4 10 6
output:
8
result:
ok single line: '8'
Test #6:
score: 0
Accepted
time: 1ms
memory: 4636kb
input:
12 1 2 3 4 5 6 7 8 9 10 11 12
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 1ms
memory: 4700kb
input:
144 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61...
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 1ms
memory: 5000kb
input:
144 78 106 141 21 115 2 14 64 124 91 117 121 30 99 144 55 94 137 38 27 40 72 59 46 50 109 84 15 87 108 52 23 74 4 140 70 63 58 105 113 77 10 35 66 130 34 96 86 16 65 12 92 83 5 95 36 45 8 79 132 75 57 98 93 119 125 26 18 136 127 73 90 3 123 53 139 142 37 103 24 133 111 143 67 76 43 114 42 44 135 22 ...
output:
699
result:
ok single line: '699'
Test #9:
score: 0
Accepted
time: 1ms
memory: 4764kb
input:
144 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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:
0
result:
ok single line: '0'
Test #10:
score: 0
Accepted
time: 0ms
memory: 4740kb
input:
1728 1728 1727 1726 1725 1724 1723 1722 1721 1720 1719 1718 1717 1716 1715 1714 1713 1712 1711 1710 1709 1708 1707 1706 1705 1704 1703 1702 1701 1700 1699 1698 1697 1696 1695 1694 1693 1692 1691 1690 1689 1688 1687 1686 1685 1684 1683 1682 1681 1680 1679 1678 1677 1676 1675 1674 1673 1672 1671 1670 ...
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 1ms
memory: 4964kb
input:
1728 802 233 421 541 844 722 70 119 697 499 1699 1323 1537 1053 551 1125 736 686 1378 630 1070 192 1650 652 291 1182 1405 848 684 1557 100 1704 329 504 611 795 1242 1548 680 1355 1693 66 479 1194 607 316 913 1343 276 701 78 737 279 804 1438 30 754 1115 745 1017 767 1046 920 683 988 1494 501 669 1658...
output:
83738
result:
ok single line: '83738'
Test #12:
score: 0
Accepted
time: 1ms
memory: 4792kb
input:
1728 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 2ms
memory: 4864kb
input:
20736 20736 20735 20734 20733 20732 20731 20730 20729 20728 20727 20726 20725 20724 20723 20722 20721 20720 20719 20718 20717 20716 20715 20714 20713 20712 20711 20710 20709 20708 20707 20706 20705 20704 20703 20702 20701 20700 20699 20698 20697 20696 20695 20694 20693 20692 20691 20690 20689 20688 ...
output:
1
result:
ok single line: '1'
Test #14:
score: 0
Accepted
time: 0ms
memory: 4936kb
input:
20736 15428 2928 14988 4279 13247 8077 8128 5263 19240 2440 3234 3008 9868 13229 657 14625 7333 17930 9043 1743 3440 7846 5030 10290 14958 1451 9866 13357 3826 15385 7304 4033 12973 16937 131 5361 2814 6706 2681 5908 9738 15648 4911 18164 12531 10392 5428 6612 15193 9154 11479 8291 1187 1136 6330 10...
output:
11906581
result:
ok single line: '11906581'
Test #15:
score: 0
Accepted
time: 1ms
memory: 4908kb
input:
20736 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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 10...
output:
0
result:
ok single line: '0'
Test #16:
score: 0
Accepted
time: 6ms
memory: 5492kb
input:
248832 248832 248831 248830 248829 248828 248827 248826 248825 248824 248823 248822 248821 248820 248819 248818 248817 248816 248815 248814 248813 248812 248811 248810 248809 248808 248807 248806 248805 248804 248803 248802 248801 248800 248799 248798 248797 248796 248795 248794 248793 248792 248791...
output:
1
result:
ok single line: '1'
Test #17:
score: 0
Accepted
time: 10ms
memory: 5412kb
input:
248832 124869 135755 12850 214130 145599 75073 35346 33333 87655 46111 222853 201944 54979 230688 13628 144356 233045 217207 157626 123582 209484 242708 191577 173182 117845 10771 93744 56439 163427 46992 103372 174039 150400 177984 244446 58937 188383 31124 16092 128575 38724 34774 204536 75835 218...
output:
1722641914
result:
ok single line: '1722641914'
Test #18:
score: 0
Accepted
time: 6ms
memory: 5444kb
input:
248832 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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 1...
output:
0
result:
ok single line: '0'
Test #19:
score: 0
Accepted
time: 10ms
memory: 5552kb
input:
300000 300000 299999 299998 299997 299996 299995 299994 299993 299992 299991 299990 299989 299988 299987 299986 299985 299984 299983 299982 299981 299980 299979 299978 299977 299976 299975 299974 299973 299972 299971 299970 299969 299968 299967 299966 299965 299964 299963 299962 299961 299960 299959...
output:
1
result:
ok single line: '1'
Test #20:
score: -100
Wrong Answer
time: 12ms
memory: 5472kb
input:
300000 239415 50154 20266 131115 94234 36028 102103 163828 247232 288414 191935 70446 292328 101071 278663 149866 15685 291862 236268 78373 298325 130058 200948 182893 276807 219715 33136 269040 46221 48212 250438 121345 179565 46706 177889 240176 94461 152264 78126 50364 161649 258824 265439 203657...
output:
-1792912633
result:
wrong answer 1st lines differ - expected: '2502054663', found: '-1792912633'