Submission #890988


Source Code Expand

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


class Segtree<T>
{
    int n;
    T[] tree;
    Func<T, T, T> f;
    T exnum;
    public Segtree(int m, Func<T, T, T> f, T ex)
    {
        this.f = f;
        this.exnum = ex;
        n = 1;
        while (n < m) n <<= 1;

        tree = new T[(n << 1) - 1];
        for (int i = 0; i < tree.Length; i++) tree[i] = ex;
    }
    public Segtree(int m, T ini, Func<T, T, T> f, T ex)
    {
        this.f = f;
        this.exnum = ex;
        n = 1;
        while (n < m) n <<= 1;

        tree = new T[(n << 1) - 1];
        for (int i = 0; i < tree.Length; i++) tree[i] = ini;
        for (int i = 0; i < m; ++i) update(i, ini);
    }
    public void update(int j, T x)
    {
        int i = j + n - 1;
        tree[i] = x;
        while (i > 0)
        {
            i = (i - 1) >> 1;
            tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
        }
    }
    public T look(int i) { return tree[i + n - 1]; }

    // [s, t]
    public T run(int s, int t) { return query(s, t + 1, 0, 0, n); }
    T query(int s, int t, int k, int l, int r)
    {
        if (r <= s || t <= l) return exnum;
        if (s <= l && r <= t) return tree[k];

        return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r));
    }
}

namespace Codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int result = 0;

            int[] arr = new int[n];
            string[] input_arr = Console.ReadLine().Split(' ');

            for(int i = 0; i<n; i++)
            {
                arr[i] = int.Parse(input_arr[i]);
            }

            for(int i = 0; i<n; i++)
            {
                if (i == arr[arr[i] - 1] - 1) result++;
            }

            Console.WriteLine(result / 2);
        }
    }
}

Submission Info

Submission Time
Task B - Friendly Rabbits
User lightseller
Language C# (Mono 4.6.2.0)
Score 200
Code Size 2039 Byte
Status AC
Exec Time 57 ms
Memory 9688 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 3
AC × 15
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt
Case Name Status Exec Time Memory
0_00.txt AC 20 ms 2776 KB
0_01.txt AC 19 ms 2648 KB
0_02.txt AC 19 ms 2648 KB
1_00.txt AC 19 ms 2648 KB
1_01.txt AC 56 ms 9688 KB
1_02.txt AC 56 ms 9688 KB
1_03.txt AC 57 ms 9688 KB
1_04.txt AC 56 ms 9688 KB
1_05.txt AC 56 ms 9688 KB
1_06.txt AC 56 ms 9688 KB
1_07.txt AC 56 ms 9688 KB
1_08.txt AC 34 ms 5976 KB
1_09.txt AC 49 ms 8536 KB
1_10.txt AC 45 ms 7640 KB
1_11.txt AC 25 ms 4056 KB