QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#872#580049#9377. Points Selection3un_larryfuncAfterlifeFailed.2024-09-21 20:37:232024-09-21 20:37:32

Details

Extra Test:

Invalid Input

input:

3
1 2 2
2 3 1
3 1 3

output:


result:

FAIL Expected EOLN (stdin, line 1)

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#580049#9377. Points SelectionAfterlifeAC ✓1341ms29236kbC++201.8kb2024-09-21 19:52:532024-09-21 19:52:54

answer

#include<bits/stdc++.h>
using namespace std;

#define int long long

using ull=unsigned long long;

using pii=pair<int,int>;

const int N=5e5+1e3+7;

vector<pii> v[N];

ull calc(int l,int r)
{
    return ull(l+r)*(r-l+1)/2;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    srand(time(NULL));
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x,y,w;
        cin>>x>>y>>w;
        // int x=rand()%n+1,y=rand()%n+1,w=rand()%n+1;
        v[x].push_back({y,w});
    }
    int cnt=0;
    long long cp=0;
    multiset<pair<int,int> > S;
    bitset<N> all;
    for(int i=0;i<n;i++)
        all.set(i,1);
    ull lastsum=0;
    ull ans=0;
    for(int x=1;x<=n;x++)
    {
        auto last=S;
        for(auto &[y,w]:v[x])
        {
            S.insert({y,w});
        }
        while(S.size()>25)
            S.erase(--S.end());
        if(last!=S)
        {
            // cp+=30,cnt++;
            bitset<N> f;
            f.set(0,1);
            lastsum=0;
            ull sum=0;
            for(auto it=S.begin(),jt=it;it!=S.end();it=jt)
            {
                jt=it;
                while(jt!=S.end()&&jt->first==it->first)
                    jt++;
                auto lf=f;
                for(auto tmp=it;tmp!=jt;tmp++)
                {
                    auto w=tmp->second;
                    f|=f<<w|f>>(n-w);
                    f&=all;
                }
                lf^=f;
                for(int i=lf._Find_first();i<n;i=lf._Find_next(i))
                    sum+=i;
                int ly=it->first;
                int ry=jt==S.end()?n:jt->first-1;
                lastsum+=sum*calc(ly,ry);
            }
        }
        ans+=lastsum*x;
    }
    cout<<ans<<"\n";
    // cout<<cp*500000/64<<endl;
    // cout<<cnt<<"\n";
}