Advertisement
Korotkodul

algo_N0.1

Mar 22nd, 2025 (edited)
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <exception>
  4. #include <cmath>
  5. #include <unordered_set>
  6. #include <vector>
  7. #include <unordered_map>
  8. #define pii pair <int, int>
  9. using namespace std;
  10.  
  11.  
  12. int main() {
  13.     int n;
  14.     cin >> n;
  15.     unordered_map <int, int> pf = {{0, -1}};
  16.     int cnt = 0;
  17.     vector <int> idx(n);
  18.     vector <pii> ans;
  19.     vector <int> a(n);
  20.     for(int i = 0; i < n; ++i) {
  21.         int el; cin >> el; a[i] = el;
  22.         cnt += el;
  23.         int dst;
  24.         auto it = pf.find(cnt);
  25.         if (it != pf.end()) {
  26.             ans.push_back(pii{pf[cnt] + 1, i});
  27.             pf[cnt] = i;
  28.         }
  29.     }
  30.     for (auto p: ans) {
  31.         cout << p.first << ' ' << p.second << "\n";
  32.     }
  33. }
  34. /*
  35. 10
  36. 3 4 -7 3 1 3 1 -4 -2 -2
  37. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement