NirvanaCeleste @ 2024-07-11 07:03:15
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500100;
long long tree[MAXN],ranks[MAXN];
long long ans,n;
struct point {
long long num,val;
} a[MAXN];
bool cmp(point q,point w) {
if(q.val == w.val) return q.num < w.num;
return q.val < w.val;
}
void add(int p,long d) {
for(; p<=n; p += p & (-p)) tree[p] += d;
}
long long sum(int p) {
long long pll = 0;
for(; p; p -= p & (-p)) pll += tree[p];
return pll;
}
int main() {
scanf("%lld\n",&n);
for(int i=1; i<=n; i++){
scanf("%lld\n",&a[i].val);
a[i].num = i;
}
sort(a+1,a+1+n,cmp);
for(int i=1; i<=n; i++) ranks[a[i].num] = i;
for(int i=n; i>=1; i--) {
ans += sum(ranks[i] - 1);
add(ranks[i],1);
}
printf("%lld\n",ans);
return 0;
}
by Kete @ 2024-07-11 11:52:42
Waiting 评测:评测请求正在等待被评测机抓取
Fetched 评测:评测请求已被评测机抓取,正在准备开始评测
Compiling 评测:正在编译中
Judging 评测:编译成功,正在评测中
Accepted 通过:程序输出完全正确
Wrong Answer 不通过:程序输出与标准答案不一致(不包括行末空格以及文件末空行)
Time Limit Exceeded 不通过:程序运行时间超过了题目限制
Memory Limit Exceeded 不通过:程序运行内存空间超过了题目限制
Runtime Error 不通过:程序运行时错误(如数组越界、被零除、运算溢出、栈溢出、无效指针等)
Compile Error 不通过:编译失败
by NirvanaCeleste @ 2024-07-12 10:26:43
@shengzhe0227 @FiraCode @Lyw_Cyq_01 @Morax_Rock @qiuribomu
明白了
传统题 文件IO:deseq 1000ms 256MiB
没用freopn...
by qiuribomu @ 2024-07-12 10:31:20
@NirvanaCeleste
是freopen