답안 #533886

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
533886 2022-03-07T14:46:25 Z idas Sails (IOI07_sails) C++11
100 / 100
62 ms 5036 KB
#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
#define all(x) (x).begin(), (x).end()
#define le(vec) vec[vec.size()-1]
#define sz(x) ((int)((x).size()))
#define pb push_back
#define s second
#define f first

using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;

const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e13;

void setIO()
{
    FAST_IO;
}

void setIO(string s)
{
    FAST_IO;
    freopen((s+".in").c_str(), "r", stdin);
    freopen((s+".out").c_str(), "w", stdout);
}

const int N=1e5+10;
set<int> st;
int n, sm;
ll p[N];

pii find_seg(int nd)
{
    return {*prev(st.lower_bound(nd)), *st.lower_bound(nd)};
}

void add(int i)
{
    p[i]++; sm++;
    if(p[i]==0){
        st.erase(i);
    }
}

void neg(int i)
{
    p[i]--; sm--;
    if(p[i]==-1){
        st.insert(i);
    }
}

int main()
{
    setIO();
    cin >> n;
    vector<pii> inf;
    int mx=0;
    FOR(i, 0, n)
    {
        int h, k;
        cin >> h >> k;
        inf.pb({h,k});
        mx=max(mx, h);
    }
    sort(all(inf));
    int lst=-1;
    st.insert(1);
    for(auto[h, k] : inf){
        if(h>lst){
            st.insert(h+1);
            p[lst+1]-=sm;
            if(p[lst+1]==0) st.erase(lst+1);
            lst=h;
        }

        int nd=lst-k+1;
        pii curs=find_seg(nd);
        if(st.count(nd)){
            add(nd); neg(lst+1);
        }
        else{
            add(curs.s); neg(lst+1);
            int dif=curs.s-nd;
            add(curs.f); neg(curs.f+dif);
        }
    }

    ll ans=0;
    FOR(i, 1, mx+1)
    {
        p[i]+=p[i-1];
        ans+=p[i]*(p[i]-1)/2;
    }

    cout << ans;
}

Compilation message

sails.cpp: In function 'int main()':
sails.cpp:78:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   78 |     for(auto[h, k] : inf){
      |             ^
sails.cpp: In function 'void setIO(std::string)':
sails.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sails.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen((s+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 716 KB Output is correct
2 Correct 11 ms 992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 2512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 1988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 2704 KB Output is correct
2 Correct 38 ms 3256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 5036 KB Output is correct
2 Correct 32 ms 2544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 3712 KB Output is correct
2 Correct 31 ms 2488 KB Output is correct