Submission #893275

# Submission time Handle Problem Language Result Execution time Memory
893275 2023-12-26T20:03:45 Z kokoue Money (IZhO17_money) C++14
0 / 100
1 ms 2392 KB
#include<bits/stdc++.h>
using namespace std;
int tree[1000000];
int n;
int a[1000000];
void update(int idx, int val)
{
    for(int i=idx;i<=n;i+=i&(-i))
    {
        tree[i]+=val;
    }
   // printf("update %d = %d\n",idx,val);
    return;
}
long long query(int idx)
{
    long long res=0;
    for(int i=idx;i>0;i-=i&(-i))
    {
        res+=tree[i];
    }
   // printf("query %d = %d\n",idx,res);
    return res;
}
long long query(int l,int r)
{
   // printf("query %d and %d\n",l,r);
    if(l==r) return 0;
    return query(r)-query(l);
}
int main()
{
    scanf("%d",&n);
    long long br=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=2;i<=n;i++)
    {
        update(i,1);
    }
    for(int i=n-1;i>0;i--)
    {
        br+=query(a[i],n);
        update(a[i],-1);
    }
    printf("%lld\n",br);
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
money.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -