CSES - KILO 2016 2/5 - Results
Submission details
Task:Invert
Sender:Feeniksi
Submission time:2016-09-13 18:59:33 +0300
Language:Java
Status:READY
Result:
Test results
testverdicttime
#11.83 sdetails
#21.11 sdetails
#3--details
#4--details
#51.23 sdetails
#6--details
#70.25 sdetails
#81.39 sdetails
#9--details
#10--details
#110.90 sdetails
#12--details
#13--details
#141.46 sdetails
#15--details
#16--details
#171.10 sdetails
#18--details
#19--details
#201.46 sdetails

Code

import java.util.Collections;
import java.util.LinkedList;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author viljampa
 */
public class kilpa22 {

    public static void main(String[] args) {
        IO io = new IO();
        LinkedList<Integer> lista = new LinkedList();
        int montako = io.nextInt();
        int inversio = 0;
        int inversiot = 0;
//        int montako = 4;
//        lista.add(2);
//        lista.add(6);
//        lista.add(3);
//        lista.add(1);
//        lista.add(1);
//        Collections.sort(lista);        
//        for (int i = 0; i < montako; i++) {
//            System.out.println(lista.get(i));
//        }

        for (int i = 0; i < montako; i++) {
            int luku = io.nextInt();
//            int luku = 4;
            if (luku == 1) {
                lista.addLast(io.nextInt());
            } else if (luku == 2) {
                lista.addFirst(io.nextInt());
            } else if (luku == 3) {
                Collections.sort(lista);
            } else if (luku == 4) {
                inversio = 0;
                LinkedList<Integer> lista2 = new LinkedList();
                for (Integer eka : lista) {
                    lista2.add(eka);
                }
                for (int j = 0; j < lista2.size(); j++) {
                    for (int k = j - 1; k >= 0; k--) {
                        inversiot = 0;
                        if (lista2.get(k) > lista2.get(k + 1)) {
                            int apu = lista2.get(k + 1);
                            lista2.set(k + 1, lista2.get(k));
                            lista2.set(k, apu);
                            inversio++;
                            inversiot++;
                        } else break;
                    }
                    if (inversiot == 0) break;
                }
                io.print(inversio + "\n");
            }
        }

        //	String a = io.next(); // Lukee seuraavan välein erotellun merkkijonon.
//	int b = io.nextInt(); // Lukee seuraavan välein erotellun int-kokonaisluvun.
//	long c = io.nextLong(); // Lukee seuraavan välein erotellun long-kokonaisluvun.
//	double d = io.nextDouble(); // Lukee seuraavan välein erotellun double-liukuluvun.
        io.close();
    }

}
//                for (Integer eka : lista) {
//                    lista2.add(eka);
//                }
//                Collections.sort(lista2);
//                int a = 0;
//                for (Integer luku1 : lista) {
//                    int monesko = 0;
//                    for (Integer luku2 : lista2) {
//                        if (luku1 > luku2) {
//                            if (monesko - a > 0) {
//                                inversio += monesko - a;
//                            }
//                        }
//                        monesko++;
//                    }
//                    a++;
//                }

Test details

Test 1

Verdict:

input
116682
2 16788
1 18822
1 33396
2 69805
...

correct output
2718
19980
51212
68871
108108
...

user output
0
0
0
0
0
...

Test 2

Verdict:

input
500000
2 98355
2 60191
1 725
2 44093
...

correct output
4591136
513858069
2568146952
3245381276
3834167771
...

user output
0
0
0
0
0
...

Test 3

Verdict:

input
279091
1 1715
2 67456
3
4
...

correct output
0
7
8
8
10
...

user output
(empty)

Test 4

Verdict:

input
500000
2 61543
1 60828
1 50355
1 40328
...

correct output
68875
35642
76306
9043
53444
...

user output
(empty)

Test 5

Verdict:

input
401545
1 20583
1 54459
2 5060
2 18660
...

correct output
7135104
67093970
87978149
240022409
353132099
...

user output
0
0
0
0
0
...

Test 6

Verdict:

input
500000
2 41157
2 37822
2 72091
3
...

correct output
2
2
2
2
5
...

user output
(empty)

Test 7

Verdict:

input
10079
2 52135
1 5407
2 94
1 37058
...

correct output
158419
6571
89379
171235
7854
...

user output
0
0
0
0
0
...

Test 8

Verdict:

input
500000
1 83689
1 70194
1 17167
2 52286
...

correct output
16433238
99620800
142458990
274873638
411495712
...

user output
0
0
0
0
0
...

Test 9

Verdict:

input
90533
2 34119
4
3
3
...

correct output
0
0
16
27
0
...

user output
(empty)

Test 10

Verdict:

input
500000
2 63136
2 11519
1 91986
1 92054
...

correct output
191
11103
16624
90718
101186
...

user output
(empty)

Test 11

Verdict:

input
323662
1 18238
1 62832
1 53482
1 43447
...

correct output
158283253
677654483
1023537391
121975751
144502380
...

user output
0
0
0
0
0
...

Test 12

Verdict:

input
500000
1 11725
4
1 99988
1 88696
...

correct output
0
21
0
0
0
...

user output
(empty)

Test 13

Verdict:

input
125498
1 65018
1 41218
2 93534
2 78789
...

correct output
41
1213
49209
27631
56275
...

user output
(empty)

Test 14

Verdict:

input
500000
2 22435
2 98738
1 57359
2 77794
...

correct output
5948069
17495286
58672750
137825207
482842950
...

user output
0
0
0
0
0
...

Test 15

Verdict:

input
343000
1 14035
3
1 36003
2 2676
...

correct output
0
0
0
0
0
...

user output
(empty)

Test 16

Verdict:

input
500000
2 67715
2 16062
1 12953
2 43464
...

correct output
14302
25179
21705
13316
26515
...

user output
(empty)

Test 17

Verdict:

input
372731
1 16333
1 58828
2 1790
2 56950
...

correct output
23264093
180691208
58859618
1007439070
357775222
...

user output
0
0
0
0
0
...

Test 18

Verdict:

input
500000
1 24800
1 30022
3
3
...

correct output
0
0
2
0
7
...

user output
(empty)

Test 19

Verdict:

input
398012
1 7709
1 12219
1 95709
1 75173
...

correct output
1733
3398
7720
34986
79727
...

user output
(empty)

Test 20

Verdict:

input
500000
1 97423
2 25928
1 85082
2 35253
...

correct output
92435834
311688637
486359207
492535988
540678377
...

user output
0
0
0
0
0
...