Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Optimizing the code

Name: Anonymous 2010-03-01 8:19

Any ideas on how I could make this program run faster?
It's supposed to run under 0.5 seconds.
In some cases it does, in others it fails.
[b]The task : [/b]

INPUT:
From the first line of the standard input read one integer (5 <= n <= 100000). Each of the following n lines will have one of the following two formats:

- 1 a - meaning that Mirko said aloud the number a, (0 <= a <= 65535).
- 2 k - meaning that Mirko asks what is the kth smallest number he has said so far. k will always be less or equal to the number of numbers Mirko has said aloud so far.

The total number of different number will not be bigger than 400, but some of the numbers can repeat!

OUTPUT:
To the standard output write one line for each of the 2 k inputs. Representing the kth smallest number at that moment.


Input:
7
1 0
1 1
1 5
2 1
2 3
1 2
2 3

Output:
0
5
2

[b]My solution : [/b]

#include <stdio.h>
int main(){
    unsigned short int * a;
        unsigned int n,j,x,y;
    int m=-1;
    scanf("%u",&n);
    a=new unsigned short int[n];
    while (n>0){
        n=n-1;
        scanf("%u %u",&x,&y);
        if (x==1){
            m=m+1;
            j=m;
            a[j]=y;
            while((j>0)&&(a[j]<a[j-1])){
                y=a[j-1];
                a[j-1]=a[j];
                a[j]=y;
                j=j-1;
            }

        }
        else printf("%u\n",a[y-1]);
    }
    delete [] a;
    return 0;
}

Name: Anonymous 2010-04-05 13:35

…………………...„„-~^^~„-„„_
………………„-^*'' : : „'' : : : : *-„
…………..„-* : : :„„--/ : : : : : : : '\
…………./ : : „-* . .| : : : : : : : : '|
……….../ : „-* . . . | : : : : : : : : |
………...\„-* . . . . .| : : : : : : : :'|
……….../ . . . . . . '| : : : : : : : :|
……..../ . . . . . . . .'\ : : : : : : : |
……../ . . . . . . . . . .\ : : : : : : :|
……./ . . . . . . . . . . . '\ : : : : : /
….../ . . . . . . . . . . . . . *-„„„„-*'
….'/ . . . . . . . . . . . . . . '|
…/ . . . . . . . ./ . . . . . . .|
../ . . . . . . . .'/ . . . . . . .'|
./ . . . . . . . . / . . . . . . .'|
'/ . . . . . . . . . . . . . . . .'|
'| . . . . . \ . . . . . . . . . .|
'| . . . . . . \„_^- „ . . . . .'|
'| . . . . . . . . .'\ .\ ./ '/ . |
| .\ . . . . . . . . . \ .'' / . '|
| . . . . . . . . . . / .'/ . . .|
| . . . . . . .| . . / ./ ./ . .|

Name: Anonymous 2010-04-05 14:10

Argh. So the false paradox Hax or My Anus thread gets threadstopped ex modestri, but this one is left alone?

Also, suddenly: /prog/ - dicks everywhere.

Name: Anonymous 2010-04-05 14:33

DICKS EVERYWHERE IN MY ANUS

Name: Anonymous 2010-04-05 15:44

>>202
Probably because whoever still has a working threadstop exploit is the same anusaurus bumping this thread every thirty seconds with his penis.

Name: Anonymous 2010-04-05 19:08

@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document url("http://dis.4chan.org/prog/") {
i { font-style: normal !important; }
}

Problem solved

Name: Anonymous 2010-04-05 19:29

>>204
Dang, and here I was blaming it on moderation.

So how badly beaten is the shitchan code in use here? I have the source somewhere and a keen eye for bugs. I could go for some conscientious vigilantism right about now.

Name: Anonymous 2010-04-05 20:32

>>206
Giz a clue when you find it!

Name: Anonymous 2010-04-05 21:28

>>207
Now that would be irresponsible.

Name: Hagar !5w1PkjmK0. 2010-04-05 21:50

Terrible.

Name: !5w1PkjmK0. 2010-04-05 21:54

Really terrible.

Name: !MjcMqTX/iM 2010-04-05 21:59

-_-

Name: bang! 2010-04-06 0:04

bangu bangu bangu

Name: hash 2010-04-06 0:05

>>212
hashishin hashishin hashishin

Name: Anonymous 2010-04-06 9:46

CFLAGS just kicked in, yo

Name: Anonymous 2010-04-06 9:57

>>214
Back to /g/, you bastard!

Name: Anonymous 2010-04-06 14:47

I feel sort of cursive today, why is that?

Name: Anonymous 2010-04-06 15:41

>>217
U MENA ITALIC

Name: Anonymous 2010-04-06 16:16

Dear >>1

Here is MEIN SOLUTION:

#!/usr/bin/env python
import sys
reduce(lambda s,_:((lambda(n,x):{0 :lambda x:x,1:lambda x:s.add(x),2:lambda x:sys.stdout.write('%d\n'%list(s)[x-1])}[n](x))(map(int,sys.stdin.readline().split(' ', 1))),s)[1],range(0,int(sys.stdin.readline())),set([]))


For an optional speed bampu please [code]import psyco[/import].

Name: Anonymous 2010-04-06 20:26

>>219
MEIN SOLUTION
Yes, but is it the FINAL SOLUTION?

Name: Anonymous 2010-04-07 5:55

>>219
SUPERMEIN SOLUTION

Name: Anonymous 2010-04-07 5:59

>>221
Hey bro, hows the autism?

Name: Anonymous 2010-04-07 6:25

THE JEW QUESTION

Name: Anonymous 2010-04-07 6:31

DIE ENDLÖSUNG DER JUDENFRAGE

Name: Anonymous 2010-04-07 6:33

SIEG HASKAL

Name: Anonymous 2010-04-07 10:05

>>222
Still aching, man.

Name: Anonymous 2010-04-07 10:47

A NEW MORNING HAS COME

Name: Anonymous 2010-04-07 11:04

>>227
Come in my Anus!

Name: Anonymous 2010-04-07 12:55

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

Name: Anonymous 2010-04-07 15:34

Bump for eternal justice

Name: Anonymous 2010-04-07 17:00

bump

Name: Anonymous 2010-04-07 22:57

Sagefault (thread bumped).

Name: Anonymous 2010-04-08 16:40

It always gets worse.

Name: Anonymous 2010-04-13 8:23

>>233
worse than what?

Name: Anonymous 2010-04-13 8:39

>>234
It was threadstopped and now it isn't.

Name: Anonymous 2010-04-13 9:08

THREADSTOP MY ANUS

Name: Anonymous 2010-04-13 13:11

can someone give me the BBCODES for this hack?

Name: Anonymous 2010-04-13 16:03

Why the hell is this thread unthreadstopped?

Name: Anonymous 2010-04-13 16:57

>>238
MrVacBob is just fucking around with us.

Name: Anonymous 2010-04-13 16:59

Goddammit, now even if we sage, it bumps the thread.

Newer Posts