fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. //Function to find first index of element in array a
  5. //greater than x, you can using upper_bound too.
  6. int upper(int a[], int l, int r, int x){
  7. int res = -1 ;
  8. while(l <= r){
  9. int m = (l+r) / 2;
  10. if(a[m] > x){
  11. res = m ;
  12. r = m - 1;
  13. }
  14. else{
  15. l = m + 1;
  16. }
  17. }
  18. return res;
  19. }
  20.  
  21. int cnt[5];
  22.  
  23. int dem(int y[], int m, int x){
  24. if(x==0) return 0;
  25. else if (x == 1) return cnt[0];
  26. int ans = cnt[0] + cnt[1];
  27. int i1 = upper(y, 0, m-1, x);
  28. if(i1!=-1) ans += m - i1;
  29. if(x==2) ans = ans - cnt[3] - cnt[4];
  30. if(x==3) ans += cnt[2];
  31. return ans;
  32. }
  33.  
  34.  
  35. void TC(){
  36. int n, m ; cin >> n >> m;
  37. memset(cnt, 0 , sizeof(cnt));
  38. int x[n], y[m];
  39. for(int i = 0; i < n; i++){
  40. cin >> x[i];
  41. }
  42. for(int i = 0; i < m; i++){
  43. cin >> y[i];
  44. if(y[i] <= 4){
  45. cnt[y[i]]++;
  46. }
  47. }
  48. sort(y, y + m);
  49. long long ans = 0;
  50. for(int i = 0; i < n; i++){
  51. ans += dem(y, m, x[i]);
  52. }
  53. cout << ans << endl;
  54. }
  55. int main(){
  56. int t; cin >> t;
  57. while(t--){
  58. TC();
  59. }
  60. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
         ^
Main.java:6: error: class, interface, or enum expected
int upper(int a[], int l, int r, int x){
^
Main.java:8: error: class, interface, or enum expected
	while(l <= r){
	^
Main.java:10: error: class, interface, or enum expected
		if(a[m] > x){
		^
Main.java:12: error: class, interface, or enum expected
			r = m - 1;
			^
Main.java:13: error: class, interface, or enum expected
		}
		^
Main.java:16: error: class, interface, or enum expected
		}
		^
Main.java:19: error: class, interface, or enum expected
}
^
Main.java:23: error: class, interface, or enum expected
int dem(int y[], int m, int x){
^
Main.java:25: error: class, interface, or enum expected
	else if (x == 1) return cnt[0];
	^
Main.java:26: error: class, interface, or enum expected
	int ans = cnt[0] + cnt[1];
	^
Main.java:27: error: class, interface, or enum expected
	int i1 = upper(y, 0, m-1, x);
	^
Main.java:28: error: class, interface, or enum expected
	if(i1!=-1) ans += m - i1;
	^
Main.java:29: error: class, interface, or enum expected
	if(x==2) ans = ans - cnt[3] - cnt[4];
	^
Main.java:30: error: class, interface, or enum expected
	if(x==3) ans += cnt[2];
	^
Main.java:31: error: class, interface, or enum expected
	return ans;
	^
Main.java:32: error: class, interface, or enum expected
}
^
Main.java:36: error: class, interface, or enum expected
	int n, m ; cin >> n >> m;
	           ^
Main.java:37: error: class, interface, or enum expected
	memset(cnt, 0 , sizeof(cnt));
	^
Main.java:38: error: class, interface, or enum expected
	int x[n], y[m];
	^
Main.java:39: error: class, interface, or enum expected
	for(int i = 0; i < n; i++){
	^
Main.java:39: error: class, interface, or enum expected
	for(int i = 0; i < n; i++){
	               ^
Main.java:39: error: class, interface, or enum expected
	for(int i = 0; i < n; i++){
	                      ^
Main.java:41: error: class, interface, or enum expected
	}
	^
Main.java:42: error: class, interface, or enum expected
	for(int i = 0; i < m; i++){
	               ^
Main.java:42: error: class, interface, or enum expected
	for(int i = 0; i < m; i++){
	                      ^
Main.java:44: error: class, interface, or enum expected
		if(y[i] <= 4){
		^
Main.java:46: error: class, interface, or enum expected
		}
		^
Main.java:49: error: class, interface, or enum expected
	long long ans = 0;
	^
Main.java:50: error: class, interface, or enum expected
	for(int i = 0; i < n; i++){
	^
Main.java:50: error: class, interface, or enum expected
	for(int i = 0; i < n; i++){
	               ^
Main.java:50: error: class, interface, or enum expected
	for(int i = 0; i < n; i++){
	                      ^
Main.java:52: error: class, interface, or enum expected
	}
	^
Main.java:54: error: class, interface, or enum expected
}
^
Main.java:56: error: class, interface, or enum expected
	int t; cin >> t;
	       ^
Main.java:57: error: class, interface, or enum expected
	while(t--){
	^
Main.java:59: error: class, interface, or enum expected
	}
	^
38 errors
stdout
Standard output is empty