\(n^2\)暴力

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long #define ON_DEBUG #ifdef ON_DEBUG #define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt","r",stdin); #else #define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ; #endif struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std; const int mod = 998244353; int fac[1000007]; int n;
inline int Cantor(int *a, int n){
int ans = 1, sum = 0;
R(i,1,n){
R(j,i+1,n){
sum += (a[i] > a[j]);
if(sum > mod) sum -= mod;
}
ans = (ans + 1ll * sum * fac[n - i] % mod) % mod;
sum = 0;
}
return ans;
} int a[1000007];
int main(){
int n;
io >> n;
fac[0] = 1;
R(i,1,n){
io >> a[i];
fac[i] = 1ll * fac[i - 1] * i % mod;
} printf("%d", Cantor(a, n)); return 0;
}

BIT优化

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long #define ON_DEBUG #ifdef ON_DEBUG #define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt","r",stdin); #else #define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ; #endif struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std; const int N = 1000007;
const int mod = 998244353; int n; int t[N];
inline void Updata(int x, int w){
for(; x <= n; x += x&-x) t[x] += w;
}
inline int Query(int x){
int sum = 0;
for(; x; x -= x&-x) sum += t[x];
return sum;
} int a[N];
int main(){
//FileOpen(); io >> n;
int fac = 1;
nR(i,n,1){
io >> a[i];
} int ans = 0;
R(i,1,n){
int sum = Query(a[i]);
ans = (ans + 1ll * fac * sum % mod) % mod;
fac = 1ll * fac * i % mod;
Updata(a[i], 1);
} printf("%d\n", ans + 1); return 0;
}

最新文章

  1. CSS——关于z-index及层叠上下文(stacking context)
  2. ((uchar*)(Img1-&gt;imageData + Img1-&gt;widthStep*pt.y))[pt.x] 的 具体含义
  3. 【USACO 3.1】Score Inflation(完全背包)
  4. mysql on Mac OS
  5. 团队开发——冲刺2.a
  6. OSX 上安装 Scrapy 的那些坑
  7. mysqli常用命令
  8. 第五章 consul key/value
  9. 腾讯云centos 7部署 dotnetcore+Angular2 实践
  10. Csharp递归和循环实现折半查找
  11. Gradle构建Java Web应用:Servlet依赖与Tomcat插件(转)
  12. BZOJ2084[Poi2010]Antisymmetry——回文自动机
  13. 转载:Eureka 开发时快速剔除失效服务
  14. 在vue-cli项目中使用bootstrap的方法示例
  15. PhotoSphereViewer 全景图
  16. 算法题目-记hulu失败的实习面试
  17. vhost-user 分析1
  18. keras搭建深度学习模型的一些小tips
  19. CXF创建webservice客户端和服务端
  20. USMT

热门文章

  1. Unicode和中午互转
  2. Machine Learning With Go 第4章:回归
  3. Acwing 428
  4. JS:函数
  5. 一文理解OpenStack网络
  6. SAP 实例 1 Images in HTML
  7. linux服务器通过mailx邮件发送附件到指定邮箱
  8. Java开发学习(六)----DI依赖注入之setter及构造器注入解析
  9. 零基础学Python:元组(Tuple)详细教程
  10. go-zero微服务实战系列(八、如何处理每秒上万次的下单请求)