Submission #109734

# Submission time Handle Problem Language Result Execution time Memory
109734 2019-05-07T20:35:30 Z nikolapesic2802 Sails (IOI07_sails) C++14
25 / 100
38 ms 3740 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T,greater<T>>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

const int N=10;
vector<pair<int,int> > sails;
struct segTree{
    vector<int> minn,maxx,lazy;
    void init()
    {
        minn.resize(4*N);
        maxx.resize(4*N);
        lazy.resize(4*N);
    }
    void prop(int i)
    {
        minn[2*i]+=lazy[i];
        minn[2*i+1]+=lazy[i];
        maxx[2*i]+=lazy[i];
        maxx[2*i+1]+=lazy[i];
        lazy[2*i]+=lazy[i];
        lazy[2*i+1]+=lazy[i];
        lazy[i]=0;
    }
    void update(int i)
    {
        minn[i]=min(minn[2*i],minn[2*i+1]);
        maxx[i]=max(maxx[2*i],maxx[2*i+1]);
    }
    void inc(int qs,int qe,int l=0,int r=N-1,int i=1)
    {
        if(qs>qe)
            return;
        if(qs>r||qe<l)
            return;
        if(qs<=l&&qe>=r)
        {
            lazy[i]++;
            minn[i]++;
            maxx[i]++;
            return;
        }
        prop(i);
        int m=(l+r)>>1;
        inc(qs,qe,l,m,2*i);
        inc(qs,qe,m+1,r,2*i+1);
        update(i);
    }
    int get(int pos,int l=0,int r=N-1,int i=1)
    {
        if(l>pos||r<pos)
            return 0;
        if(l==pos&&r==pos)
            return minn[i];
        prop(i);
        int m=(l+r)>>1;
        return get(pos,l,m,2*i)+get(pos,m+1,r,2*i+1);
    }
    int getfirst(int vr,int l=0,int r=N-1,int i=1)
    {
        if(l==r)
        {
            assert(minn[i]==vr&&maxx[i]==vr);
            return l;
        }
        prop(i);
        int m=(l+r)>>1;
        if(maxx[2*i]>=vr)
            return getfirst(vr,l,m,2*i);
        else
            return getfirst(vr,m+1,r,2*i+1);
    }
    int getlast(int vr,int l=0,int r=N-1,int i=1)
    {
        if(l==r)
        {
            assert(minn[i]==vr&&maxx[i]==vr);
            return l;
        }
        prop(i);
        int m=(l+r)>>1;
        if(minn[2*i+1]<=vr)
            return getlast(vr,m+1,r,2*i+1);
        else
            return getlast(vr,l,m,2*i);
    }
    void add(int h,int k)
    {
        //printf("%i %i\n",h,k);
        int start=N-h;
        //printf("%i\n",start);
        int koji=get(start+k-1);
        int l=max(start,getfirst(koji)),r=getlast(koji);
        int ostalo=start+k-l;
        inc(start,l-1);
        inc(r-ostalo+1,r);
        //print();
        //printf("\n");
    }
    void print(int l=0,int r=N-1,int i=1)
    {
        if(l==r)
        {
            printf("%i ",minn[i]);
            return;
        }
        prop(i);
        int m=(l+r)>>1;
        print(l,m,2*i);
        print(m+1,r,2*i+1);
    }
    ll getres(int l=0,int r=N-1,int i=1)
    {
        if(l==r)
            return (ll)minn[i]*(minn[i]-1)/2;
        prop(i);
        int m=(l+r)>>1;
        return getres(l,m,2*i)+getres(m+1,r,2*i+1);
    }
}st;
int main()
{
    //freopen("in.txt","r",stdin);
    st.init();
    int n;
	scanf("%i",&n);
	for(int i=0;i<n;i++)
    {
        int a,b;
        scanf("%i %i",&a,&b);
        sails.pb({a,b});
    }
    sort(all(sails));
    for(auto p:sails)
        st.add(p.f,p.s);
    printf("%lld\n",st.getres());
    return 0;
}

Compilation message

sails.cpp: In function 'int main()':
sails.cpp:149:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
sails.cpp:153:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i %i",&a,&b);
         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 1024 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Runtime error 20 ms 2040 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 30 ms 2796 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 34 ms 3328 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 38 ms 3740 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -