Advertisement
Josif_tepe

Untitled

Mar 15th, 2021
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <map>
  6. using namespace std;
  7. int main(){
  8.     long long n;
  9.     cin>>n;
  10.     int niza[n];
  11.     for(int i = 0; i < n; i++){
  12.         cin>>niza[i];
  13.     }
  14.     long long sz = 0;
  15.     long long answer = n * (n + 1) / 2;
  16.     for(int i = 0; i < n; i++) {
  17.         if(niza[i] != 0) {
  18.             sz += 1;
  19.         }
  20.         else {
  21.             answer -= ((sz) * (sz + 1) / 2);
  22.             sz = 0;
  23.            
  24.         }
  25.     }
  26.    
  27.     answer -= ((sz) * (sz + 1) / 2);
  28.  
  29.     cout << answer << endl;
  30.  
  31.     return 0;
  32. }
  33.  
  34. /*
  35. 5
  36.  4, 2, 0, 1, 3
  37.  
  38.  **/
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement