Submission #1730831
Source Code Expand
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define fi first #define mp make_pair typedef long long ll; typedef pair<ll,int> ii; typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds; pbds pos,neg; int timer; ll len[100011]; ll shiftpos,shiftneg; void addpos(ll x){pos.insert(mp(x-shiftpos,timer++));} void addneg(ll x){neg.insert(mp(x-shiftneg,timer++));} int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; ll m=0; ll c=0; for(int i=0;i<n;i++) { ll l,r; cin>>l>>r; len[i]=r-l; if(i>0){shiftpos+=len[i-1]; c-=len[i-1]*m;} shiftneg-=len[i];addpos(l); addpos(l); auto it=pos.begin(); ll res=it->fi+shiftpos; pos.erase(pos.begin()); addneg(res); ll neglas=prev(neg.end())->fi+shiftneg; ll posles=pos.begin()->fi+shiftpos; if(!neg.empty()&&neglas>posles) { neg.erase(prev(neg.end())); pos.erase(pos.begin()); addpos(neglas); addneg(posles); } m++; c-=l; } while(m>0) { c+=(*prev(pos.end())).fi+shiftpos; m--; pos.erase(prev(pos.end())); } cout<<c<<'\n'; }
Submission Info
Submission Time | |
---|---|
Task | E - NarrowRectangles |
User | zscoder |
Language | C++14 (GCC 5.4.1) |
Score | 1000 |
Code Size | 1205 Byte |
Status | AC |
Exec Time | 324 ms |
Memory | 13568 KB |
Judge Result
Set Name | Sample | Subtask | All | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | 700 / 700 | ||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt |
Subtask | 0_000, 0_001, 0_004, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 2_018.txt, 2_019.txt, 2_020.txt, 2_021.txt, 2_022.txt, 2_023.txt, 2_024.txt, 2_025.txt, 2_026.txt, 2_027.txt, 2_028.txt, 2_029.txt, 2_030.txt, 2_031.txt, 2_032.txt, 2_033.txt, 2_034.txt, 2_035.txt, 2_036.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 1 ms | 256 KB |
0_001.txt | AC | 1 ms | 256 KB |
0_002.txt | AC | 1 ms | 256 KB |
0_003.txt | AC | 1 ms | 256 KB |
0_004.txt | AC | 1 ms | 256 KB |
1_005.txt | AC | 2 ms | 384 KB |
1_006.txt | AC | 2 ms | 384 KB |
1_007.txt | AC | 2 ms | 384 KB |
1_008.txt | AC | 2 ms | 384 KB |
1_009.txt | AC | 2 ms | 384 KB |
1_010.txt | AC | 2 ms | 384 KB |
1_011.txt | AC | 2 ms | 384 KB |
1_012.txt | AC | 2 ms | 384 KB |
1_013.txt | AC | 2 ms | 384 KB |
1_014.txt | AC | 2 ms | 384 KB |
1_015.txt | AC | 2 ms | 384 KB |
1_016.txt | AC | 2 ms | 384 KB |
1_017.txt | AC | 2 ms | 384 KB |
2_018.txt | AC | 321 ms | 13568 KB |
2_019.txt | AC | 261 ms | 13568 KB |
2_020.txt | AC | 324 ms | 13568 KB |
2_021.txt | AC | 136 ms | 13568 KB |
2_022.txt | AC | 138 ms | 13568 KB |
2_023.txt | AC | 135 ms | 13568 KB |
2_024.txt | AC | 137 ms | 13568 KB |
2_025.txt | AC | 138 ms | 13568 KB |
2_026.txt | AC | 133 ms | 13568 KB |
2_027.txt | AC | 135 ms | 13568 KB |
2_028.txt | AC | 134 ms | 13568 KB |
2_029.txt | AC | 135 ms | 13568 KB |
2_030.txt | AC | 135 ms | 13568 KB |
2_031.txt | AC | 154 ms | 13568 KB |
2_032.txt | AC | 158 ms | 13568 KB |
2_033.txt | AC | 152 ms | 13568 KB |
2_034.txt | AC | 157 ms | 13568 KB |
2_035.txt | AC | 306 ms | 13568 KB |
2_036.txt | AC | 318 ms | 13568 KB |