답안 #399791

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
399791 2021-05-06T15:40:52 Z Fidisk Pilot (NOI19_pilot) C++14
0 / 100
3 ms 332 KB
#include <bits/stdc++.h>
using namespace std;

#define oo 1e15
#define fi first
#define se second
#define sp(iiii) setprecision(iiii)
#define IO ios_base::sync_with_stdio(false); cin.tie(0)
#define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa))
#define cntbit(xxxx) __builtin_popcount(xxxx)
#define getbit(xxxx,aaaa) ((xxxx>>(aaaa-1))&1)

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
typedef pair<long long,long long> pll;
typedef pair<pair<long long,long long>,long long> plll;
typedef pair<pair<long long,long long>,pair<long long,long long>> pllll;
typedef pair<pair<long long,long long>,bool> pllb;

const ll base=361;
const ll mod=1e9+7;
const ld eps=1e-5;
const ll maxn=1e6;

ll n,m,i,a[5000009],k,b[5000009],r[5000009],l[5000009],j,ans,pre[5000009];
vector<pll> g;
vector<ll> q;

int main(){
    IO;
    #ifndef ONLINE_JUDGE
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    #else
    #endif
    cin>>n>>m;
    for (i=1;i<=n;i++) {
        cin>>a[i];
    }
    for (i=1;i<=n;i++) {
        while (!q.empty()&&a[q.back()]<=a[i]) {
            r[q.back()]=i-1;
            q.pop_back();
        }
        q.push_back(i);
    }
    while (!q.empty()) {
        r[q.back()]=n;
        q.pop_back();
    }
    for (i=1;i<=n;i++) {
        while (!q.empty()&&a[q.back()]<=a[i]) {
            r[q.back()]=i-1;
            q.pop_back();
        }
        q.push_back(i);
    }
    while (!q.empty()) {
        r[q.back()]=n;
        q.pop_back();
    }
    for (i=n;i>=1;i--) {
        while (!q.empty()&&a[q.back()]<a[i]) {
            l[q.back()]=i+1;
            q.pop_back();
        }
        q.push_back(i);
    }
    while (!q.empty()) {
        l[q.back()]=1;
        q.pop_back();
    }
    for (i=1;i<=n;i++) {
        g.push_back({a[i],(i-l[i]+1)*(r[i]-i+1)});
    }
    sort(g.begin(),g.end());
    for (i=1;i<=n;i++) {
        b[i]=g[i-1].fi;
        pre[i]=pre[i-1]+g[i-1].se;
    }
    for (i=1;i<=m;i++) {
        cin>>k;
        ans=0;
        for (j=n;j>0;j/=2) {
            while (ans+j<=n&&k>=b[ans+j]) {
                ans+=j;
            }
        }
        cout<<pre[ans]<<'\n';
    }
}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   35 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
pilot.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   36 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -