Submission #1196949

#TimeUsernameProblemLanguageResultExecution timeMemory
1196949YassirSalamaStrange Device (APIO19_strange_device)C++20
0 / 100
404 ms109768 KiB
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define int long long using ull=unsigned long long; using ll=long long; using pii=pair<int,int>; const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; const int mod=1e9+7; #define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n"; template <typename T> istream& operator>>(istream& is, vector<T> &a) { copy_n(istream_iterator<T>(is), a.size(), a.begin()); return is;} #ifdef IOI template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cout << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); } #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__); #else #define dbg(...) 1337; #endif #define pb push_back #define F first #define S second #define all(v) v.begin(),v.end() vector<vector<int>> merge(vector<vector<int>>& intervals) { sort(intervals.begin(), intervals.end()); vector<vector<int>> merged; for (auto interval : intervals) { // if the list of merged intervals is empty or if the current // interval does not overlap with the previous, simply append it. if (merged.empty() || merged.back()[1] < interval[0]) { merged.push_back(interval); } // otherwise, there is overlap, so we merge the current and previous // intervals. else { merged.back()[1] = max(merged.back()[1], interval[1]); } } return merged; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,a,b; cin>>n>>a>>b; vector<vector<int>> v; for(int i = 0;i<n;i++){ int l,r; cin>>l>>r; l<<=1; r<<=1; l%=a; r%=a; if(l<=r){ v.pb({l,r}); }else{ v.pb({l,a-1}); v.pb({0,r}); } } vector<vector<int>> ans = merge(v); int sum = 0; for(int i = 0;i<ans.size();i++){ int t = ans[i][1]-ans[i][0]+1; sum += (t+1)/2; } cout<<sum<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...