답안 #40836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
40836 2018-02-08T18:35:19 Z Hassoony Vudu (COCI15_vudu) C++14
0 / 140
1000 ms 65536 KB
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef double D;
const ll inf=(1ll<<61);
const int mod=1e9+7;
const int MX=1e6+9;
int n,bit[MX];
int a[MX];
ll p;
map<ll,int>hashy;
void add(int x){
    while(x<MX){
        bit[x]++;
        x+=x&-x;
    }
}
int get(int x){
    int ret=0;
    while(x){
        ret+=bit[x];
        x-=x&-x;
    }
    return ret;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    ll sum=0;
    scanf("%lld",&p);
    for(int i=1;i<=n;i++){
        sum+=a[i];
        sum-=p;
        hashy[sum]=1;
    }
    hashy[0]=1;
    int tt=0;
    for(auto pp:hashy){
        hashy[pp.first]=++tt;
    }
    add(hashy[0]);
    ll ans=0;
    int x;
    for(int i=1;i<=n;i++){
        sum+=a[i];
        sum-=p;
        x=hashy[sum];
  //      cout<<prf[i]<<" ";
        ans+=get(x);
        add(x);
    }
//    cout<<endl;
    cout<<ans<<endl;
}

Compilation message

vudu.cpp: In function 'int main()':
vudu.cpp:28:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
vudu.cpp:30:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
                          ^
vudu.cpp:33:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&p);
                     ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1080 ms 892 KB Time limit exceeded
2 Execution timed out 1076 ms 900 KB Time limit exceeded
3 Execution timed out 1081 ms 1040 KB Time limit exceeded
4 Execution timed out 1050 ms 65536 KB Time limit exceeded
5 Execution timed out 1063 ms 65536 KB Time limit exceeded
6 Execution timed out 1076 ms 65536 KB Time limit exceeded
7 Execution timed out 1027 ms 65536 KB Time limit exceeded
8 Execution timed out 1058 ms 65536 KB Time limit exceeded
9 Execution timed out 1069 ms 65536 KB Time limit exceeded
10 Execution timed out 1080 ms 65536 KB Time limit exceeded