답안 #311815

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
311815 2020-10-11T19:51:53 Z lukameladze Interval Collection (CCO20_day2problem2) C++14
0 / 25
1312 ms 459800 KB
# include <bits/stdc++.h>
using namespace std;
# define mnri first.second
#define mxle  first.first
pair <pair <long long, long long> , long long>  tree[4000005];
long long  x,l,r,le1,ri1,ans,q,mnr,mxl,mx=1000005;
char ch;
multiset<long long>::iterator it;
multiset< long long> le,ri,ms1[1000005],ms2[1000005];
void update(long long node, long long le, long long ri, long long idx, long long val, int ty)
{
    
    if (le>idx || ri<idx) return;
    if (le==ri)
    {
        if (ty==0)
        {
            tree[node].mnri=val;
        }
        else tree[node].mxle=val;
        tree[node].second=tree[node].mnri-tree[node].mxle;
        return;
    }
    long long mid=(le+ri)/2;
    update(2*node,le,mid,idx,val, ty);
    update(2*node+1, mid+1, ri, idx, val, ty);
    tree[node].mnri=min(tree[2*node].mnri, tree[2*node+1].mnri);
    tree[node].mxle=max(tree[2*node].mxle, tree[2*node+1].mxle);
    x=min(tree[2*node].second, tree[2*node+1].second);
    tree[node].second=min(x,tree[2*node+1].mnri-tree[2*node].mxle);
}
int main()
{
    std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>q;
    for (long long i=1; i<=4*1000005; i++)
    {
        tree[i].mnri=1e9;
        tree[i].mxle=-1e9;
        tree[i].second=2e9;
    }
    while (q--)
    {
        cin>>ch>>l>>r;
        if (ch=='R')
        {
            le.erase(le.find(l));
            ri.erase(ri.find(r));
            ms1[l].erase(ms1[l].find(r));
            ms2[r].erase(ms2[r].find(l));
            if (!ms1[l].size()) ms1[l].insert(1e9);
            if (!ms2[r].size()) ms2[r].insert(-1e9);
            mnr=*ms1[l].begin();
            update(1,1,mx,l,mnr,0);
            
                it=ms2[r].end();
                it--;
            mxl=*it;
            update(1,1,mx,r,mxl,1);
        }
        else
        {
            ms1[l].insert(r);
            ms2[r].insert(l);
            le.insert(l);
            ri.insert(r);
            mnr=*ms1[l].begin();
            it=ms2[r].end();
            it--;
            mxl=*it;
            update(1,1,mx,l,mnr,0);
            update(1,1,mx,r,mxl,1);
        }
       it=le.end();
       it--;
        mxl=*it;
        mnr=*(ri.begin());
        if (mnr<=mxl)
        {
            cout<<tree[1].second<<endl;
        }
        else
        {
            ri1=*(ms1[mxl].begin());
            it=ms2[mnr].end();
            it--;
            le1=*it;
            cout<<ri1-le1<<endl;
        }
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:38:21: warning: iteration 4000004 invokes undefined behavior [-Waggressive-loop-optimizations]
   38 |         tree[i].mnri=1e9;
      |         ~~~~~~~~~~~~^~~~
Main.cpp:36:26: note: within this loop
   36 |     for (long long i=1; i<=4*1000005; i++)
      |                         ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 345 ms 381108 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 345 ms 381108 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 345 ms 381108 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1312 ms 459800 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 345 ms 381108 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -