题解 | #The Grand Tournament#
The Grand Tournament
https://ac.nowcoder.com/acm/contest/18713/A
两个数组 一个存原数组 一个存排序后的数组
用两个变量分别存数的和,相同时即可分为一组,即组内和相同 数相同
#include<bits/stdc++.h> using namespace std; #define eb emplace_back #define mem(a, b) memset(a, b, sizeof(a)) #define DEBUG(x) cerr << #x << '=' << x << endl #define repl(i,x,y) for(int i=x;i<=y; ++i) #define repr(i,k,n) for(int i=x;i>=y; --i) template <typename T> inline void read(T& f){f = 0;T fu = 1;char c = getchar();while (c < '0' || c > '9'){if (c == '-'){fu = -1;}c = getchar();}while (c >= '0' && c <= '9'){f = (f << 3) + (f << 1) + (c & 15);c = getchar();}f *= fu;} template <typename T> void print(T x){if (x < 0) putchar('-'), x = -x;if (x < 10) putchar(x + 48);else print(x / 10), putchar(x % 10 + 48);} template <typename T> void print(T x, char t){print(x);putchar(t);} typedef long long ll; const int M = 1e9+7; const int N = 1e6+100; const int mod = 998244353; const int maxn = 100; int n, m, t,l,k,r,c; int a[N],b[N]; signed main() { read(n); int ans=0; for(int i=1;i<=n;i++) { read(a[i]); b[i]=a[i]; } sort(b+1,b+1+n); ll sum1=0; ll sum2=0; for(int i=1;i<=n;i++) { sum1+=a[i]; sum2+=b[i]; if(sum1==sum2) ans++; } cout<<ans<<endl; }