1426D - Non-zero Segments - CodeForces Solution


constructive algorithms data structures greedy sortings *1500

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d", &n);
    int l[n];
    for(int i = 0; i < n; i++){
        scanf("%d", l+i);
    }
    int ans = 0;
    map<long long, int> m;
    long long x = 0;
    m[0] = 1;
    for(int i = 0; i < n; i++){
        x += l[i];
        if(m[x]){
            ans++;
            m.clear();
            x = l[i];
            m[0] = 1;
        }
        m[x] = 1;
    }
    printf("%d\n", ans);
}


Comments

Submit
0 Comments
More Questions

1667B - Optimal Partition
1668B - Social Distance
88B - Keyboard
580B - Kefa and Company
960A - Check the string
1220A - Cards
897A - Scarborough Fair
1433B - Yet Another Bookshelf
1283B - Candies Division
1451B - Non-Substring Subsequence
1408B - Arrays Sum
1430A - Number of Apartments
1475A - Odd Divisor
1454B - Unique Bid Auction
978C - Letters
501B - Misha and Changing Handles
1496A - Split it
1666L - Labyrinth
1294B - Collecting Packages
1642B - Power Walking
1424M - Ancient Language
600C - Make Palindrome
1669D - Colorful Stamp
1669B - Triple
1669A - Division
1669H - Maximal AND
1669E - 2-Letter Strings
483A - Counterexample
3C - Tic-tac-toe
1669F - Eating Candies