<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=3748_-_Secvente5</id>
	<title>3748 - Secvente5 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=3748_-_Secvente5"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=3748_-_Secvente5&amp;action=history"/>
	<updated>2026-06-17T09:31:41Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://wiki.universitas.ro/index.php?title=3748_-_Secvente5&amp;diff=9060&amp;oldid=prev</id>
		<title>Miawinator: Pagină nouă: Se consideră un șir cu &lt;code&gt;N&lt;/code&gt; elemente numere întregi. Definim următoarele noțiuni:  * secvență în șir = elemente situate pe poziții consecutive în șir * lungimea unei secvențe = numărul de elemente care o formează * suma unei secvențe = suma elementelor care o formează * secvența nebanală = secvența de lungime cel puțin egală cu &lt;code&gt;2&lt;/code&gt; * N-secvență = secvență a cărei sumă este divizibilă cu &lt;code&gt;N&lt;/code&gt; (secvența poate fi și b...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=3748_-_Secvente5&amp;diff=9060&amp;oldid=prev"/>
		<updated>2024-01-05T02:34:52Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: Se consideră un șir cu &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; elemente numere întregi. Definim următoarele noțiuni:  * secvență în șir = elemente situate pe poziții consecutive în șir * lungimea unei secvențe = numărul de elemente care o formează * suma unei secvențe = suma elementelor care o formează * secvența nebanală = secvența de lungime cel puțin egală cu &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt; * N-secvență = secvență a cărei sumă este divizibilă cu &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; (secvența poate fi și b...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Se consideră un șir cu &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; elemente numere întregi. Definim următoarele noțiuni:&lt;br /&gt;
&lt;br /&gt;
* secvență în șir = elemente situate pe poziții consecutive în șir&lt;br /&gt;
* lungimea unei secvențe = numărul de elemente care o formează&lt;br /&gt;
* suma unei secvențe = suma elementelor care o formează&lt;br /&gt;
* secvența nebanală = secvența de lungime cel puțin egală cu &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt;&lt;br /&gt;
* N-secvență = secvență a cărei sumă este divizibilă cu &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; (secvența poate fi și banală)&lt;br /&gt;
* N-secvență nebanală = secvență nebanală a cărei sumă este divizibilă cu &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Cerințe =&lt;br /&gt;
Scrieți un program care să citească numărul natural &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; și apoi șirul de &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; elemente. Programul determină:&lt;br /&gt;
&lt;br /&gt;
# numărul de N-secvențe nebanale, din șir;&lt;br /&gt;
# cea mai mare lungime a unei N-secvențe din șir;&lt;br /&gt;
# cea mai mare sumă a unei N-secvențe din șir.&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fișierul de intrare &amp;lt;code&amp;gt;input.txt&amp;lt;/code&amp;gt; conține pe prima linie numere naturale &amp;lt;code&amp;gt;C&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; separate printr-un singur spațiu. &amp;lt;code&amp;gt;C&amp;lt;/code&amp;gt; reprezentând cerința care trebuie rezolvată (&amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt; sau &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Date de ieșire =&lt;br /&gt;
Fișierul &amp;lt;code&amp;gt;output.txt&amp;lt;/code&amp;gt; va conține pe prima linie un număr natural reprezentând:&lt;br /&gt;
&lt;br /&gt;
* dacă &amp;lt;code&amp;gt;C = 1&amp;lt;/code&amp;gt;, numărul de &amp;lt;code&amp;gt;N-secvențe nebanale&amp;lt;/code&amp;gt; din șir (răspunsul la cerința &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;);&lt;br /&gt;
* dacă &amp;lt;code&amp;gt;C = 2&amp;lt;/code&amp;gt;, cea mai mare lungime a unei &amp;lt;code&amp;gt;N-secvențe&amp;lt;/code&amp;gt; din șir (răspunsul la cerința &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt;);&lt;br /&gt;
* dacă &amp;lt;code&amp;gt;C = 3&amp;lt;/code&amp;gt;, cea mai mare sumă a unei &amp;lt;code&amp;gt;N-secvențe&amp;lt;/code&amp;gt; din șir (răspunsul la cerința &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Restricții și precizări =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;2 ≤ N ≤ 100.000&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exemplul 1 ==&lt;br /&gt;
input.txt:&lt;br /&gt;
&lt;br /&gt;
1 10&lt;br /&gt;
&lt;br /&gt;
-9 -3 4 -10 -1 -16 18 18 -10 50&lt;br /&gt;
&lt;br /&gt;
output.txt:&lt;br /&gt;
&lt;br /&gt;
8&lt;br /&gt;
&lt;br /&gt;
Explicație:&lt;br /&gt;
&lt;br /&gt;
Se rezolvă cerința &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;. Șirul are &amp;lt;code&amp;gt;N=10&amp;lt;/code&amp;gt; elemente întregi: &amp;lt;code&amp;gt;-9, -3, 4, -10, -1, -16, 18, 18, -10, 50&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Cele &amp;lt;code&amp;gt;N-secvențe nebanale&amp;lt;/code&amp;gt; sunt &amp;lt;code&amp;gt;(-3, 4, -10, -1)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;(-16, 18, 18)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;(-10, 50)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;(-16, 18, 18, -10)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;(-16, 18, 18, -10, 50)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;(-3, 4, -10, -1, -16, 18, 18)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;(-3, 4, -10, -1, -16, 18, 18, -10)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;(-3, 4, -10, -1, -16, 18, 18, -10, 50)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Exemplul 2 ==&lt;br /&gt;
input.txt:&lt;br /&gt;
&lt;br /&gt;
2 10&lt;br /&gt;
&lt;br /&gt;
9 -3 4 -10 -1 -16 18 18 -10 50&lt;br /&gt;
&lt;br /&gt;
output.txt:&lt;br /&gt;
&lt;br /&gt;
9&lt;br /&gt;
&lt;br /&gt;
Explicație:&lt;br /&gt;
&lt;br /&gt;
Se rezolvă cerința &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt;. Șirul are &amp;lt;code&amp;gt;N=10&amp;lt;/code&amp;gt; elemente întregi: &amp;lt;code&amp;gt;-9, -3, 4, -10, -1, -16, 18, 18, -10, 50&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Cea mai lungă dintre aceste secvențe este N-secvența &amp;lt;code&amp;gt;(-3, 4,-10,-1,-16,18,18,-10,50)&amp;lt;/code&amp;gt;. Lungimea acestei secvențe este &amp;lt;code&amp;gt;9&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Exemplul 3 ==&lt;br /&gt;
input.txt:&lt;br /&gt;
&lt;br /&gt;
3 10&lt;br /&gt;
&lt;br /&gt;
9 -3 4 -10 -1 -16 18 18 -10 50&lt;br /&gt;
&lt;br /&gt;
output.txt:&lt;br /&gt;
&lt;br /&gt;
60&lt;br /&gt;
&lt;br /&gt;
Explicație:&lt;br /&gt;
&lt;br /&gt;
Se rezolvă cerința &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;. Șirul are &amp;lt;code&amp;gt;N=10&amp;lt;/code&amp;gt; elemente întregi: &amp;lt;code&amp;gt;-9, -3, 4, -10, -1, -16, 18, 18, -10, 50&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Suma maximă a unei secvente este &amp;lt;code&amp;gt;60&amp;lt;/code&amp;gt; ( suma N-secvenței: &amp;lt;code&amp;gt;-16,18,18,-10,50&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Exemplul 4 ==&lt;br /&gt;
input.txt:&lt;br /&gt;
&lt;br /&gt;
3 999999999999&lt;br /&gt;
&lt;br /&gt;
-9 -3 4 -10 -1 -16 18 18 -10 50&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
Input-ul nu convine conditiilor&lt;br /&gt;
&lt;br /&gt;
== Rezolvare ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python3&amp;quot; line=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
def verificare(n):&lt;br /&gt;
    if not(2&amp;lt;=n&amp;lt;=100000):&lt;br /&gt;
        print(&amp;quot;Input-ul nu convine conditiilor&amp;quot;)&lt;br /&gt;
        exit()&lt;br /&gt;
&lt;br /&gt;
with open(&amp;quot;input.txt&amp;quot;, &amp;quot;r&amp;quot;) as f, open(&amp;quot;output.txt&amp;quot;, &amp;quot;w&amp;quot;) as g:&lt;br /&gt;
    C, N = map(int, f.readline().split())&lt;br /&gt;
    verificare(N)&lt;br /&gt;
    v = [0] * 100001&lt;br /&gt;
    prim = [0] * 100001&lt;br /&gt;
    ult = [0] * 100001&lt;br /&gt;
    s = [0] * 100001&lt;br /&gt;
    rest = [0] * 100001&lt;br /&gt;
    nrv = 0&lt;br /&gt;
    nrs = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    sc = 0&lt;br /&gt;
    r = 0&lt;br /&gt;
    smax = 0&lt;br /&gt;
    lgmax = 0&lt;br /&gt;
    lg = 0&lt;br /&gt;
    srest = [0] * 100001&lt;br /&gt;
    sumaseccurenta = 0&lt;br /&gt;
&lt;br /&gt;
    l=list(map(int, f.readline().split()))&lt;br /&gt;
&lt;br /&gt;
    for i in range(1, N + 1):&lt;br /&gt;
        x = l[i-1]&lt;br /&gt;
        if x % N == 0:&lt;br /&gt;
            nrv += 1&lt;br /&gt;
            smax = max(smax, x)&lt;br /&gt;
        s[i] = s[i - 1] + x&lt;br /&gt;
        r = s[i] % N&lt;br /&gt;
        if r == 0:&lt;br /&gt;
            smax = max(smax, s[i])&lt;br /&gt;
            lgmax = max(lgmax, i)&lt;br /&gt;
        if r &amp;lt; 0:&lt;br /&gt;
            r = N + r&lt;br /&gt;
        rest[r] += 1&lt;br /&gt;
        if prim[r] == 0:&lt;br /&gt;
            ult[r] = prim[r] = i&lt;br /&gt;
        ult[r] = i&lt;br /&gt;
        lg = i - prim[r]&lt;br /&gt;
        if lg &amp;gt; 1 and lg &amp;gt; lgmax:&lt;br /&gt;
            lgmax = lg&lt;br /&gt;
        if rest[r] == 1:&lt;br /&gt;
            srest[r] = s[i]&lt;br /&gt;
        else:&lt;br /&gt;
            if s[i] &amp;lt; srest[r]:&lt;br /&gt;
                srest[r] = s[i]&lt;br /&gt;
            smax = max(smax, s[i] - srest[r])  # suma N-secventei curecte este s[i]-srest[r]&lt;br /&gt;
&lt;br /&gt;
    nrs = rest[0]&lt;br /&gt;
    for i in range(N):&lt;br /&gt;
        nrs = nrs + rest[i] * (rest[i] - 1) // 2&lt;br /&gt;
    nrs = nrs - nrv&lt;br /&gt;
&lt;br /&gt;
    if C == 1:&lt;br /&gt;
        g.write(str(nrs) + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    elif C == 2:&lt;br /&gt;
        g.write(str(lgmax) + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        g.write(str(smax) + &amp;quot;\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Miawinator</name></author>
	</entry>
</feed>