Created
October 28, 2012 23:16
-
-
Save m00dy/3970382 to your computer and use it in GitHub Desktop.
InterviewStreet Quadrntic Queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.util.Scanner; | |
public class Solution { | |
/** | |
* @param args | |
* @throws IOException | |
*/ | |
public static void main(String[] args) throws IOException { | |
// TODO Auto-generated method stub | |
Scanner scan = new Scanner(System.in); | |
int N = scan.nextInt(); | |
byte[] regions = new byte[N]; | |
for(int i=0;i<N;i++) | |
{ | |
int x = scan.nextInt(); | |
int y = scan.nextInt(); | |
if(x>0 && y>0){ | |
regions[i]=0x11; //1.bolge | |
} | |
else if(x>0 && y<0){ | |
regions[i]=0x10; //4.bolge | |
} | |
else if(x<0 && y>0){ | |
regions[i]=0x01; //2.bolge | |
} | |
else{ | |
regions[i]=0x00; //3.bolge | |
} | |
} | |
int Q = scan.nextInt(); | |
char[] queries; | |
queries = new char[Q]; | |
int numbers[][] = new int[Q][2]; | |
String temp; | |
for(int i=0;i<Q;i++) | |
{ | |
temp = scan.next(); | |
queries[i] = temp.toCharArray()[0]; | |
numbers[i][0] = scan.nextInt(); | |
numbers[i][1] = scan.nextInt(); | |
if(queries[i] == 'X') | |
{ | |
X(regions,numbers[i][0],numbers[i][1]); | |
} | |
else if(queries[i] == 'Y'){ | |
Y(regions,numbers[i][0],numbers[i][1]); | |
} | |
else if(queries[i] == 'C') | |
{ | |
C(regions,numbers[i][0],numbers[i][1]); | |
} | |
} | |
} | |
public static void X(byte[] arr,int start,int stop) | |
{ | |
for(int i = start-1;i<stop;i++) | |
{ | |
arr[i] ^=0x01; | |
} | |
} | |
public static void Y(byte[] arr,int start,int stop) | |
{ | |
for(int i = start-1;i<stop;i++) | |
{ | |
arr[i] ^=0x10; | |
} | |
} | |
public static void C(byte[] arr,int start,int stop) | |
{ | |
int one =0; | |
int two =0; | |
int three=0; | |
int four=0; | |
for(int i = start-1;i<stop;i++) | |
{ | |
switch(arr[i]) | |
{ | |
case 0x11: | |
one++; | |
break; | |
case 0x10: | |
four++; | |
break; | |
case 0x01: | |
two++; | |
break; | |
case 0x00: | |
three++; | |
} | |
} | |
System.out.println(""+one+" "+two+" "+three+" "+four); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can see the implementation for X,Y is pretty, but I don't see in any sense this is related with graph