fork download
  1. // 1) count increasing triples
  2. for(int j = 0; j < n; j++) {
  3. int smaller = 0, bigger = 0;
  4. for(int i = 0; i < j; i++) {
  5. if(a[i] < a[j]) {
  6. smaller++;
  7. }
  8. }
  9. for(int k = j + 1; k < n; k++) {
  10. if(a[k] > a[j]) {
  11. bigger++;
  12. }
  13. }
  14. answer += smaller * bigger;
  15. }
  16.  
  17.  
  18. // 4-SUM
  19. set<int> pairs; // pairs up to i-1
  20. for(int i = 0; i < n; i++) {
  21. for(int j = i + 1; j < n; j++) {
  22. int missing = x - a[i] - a[j];
  23. if(pairs.count(missing)) {
  24. printf("YES");
  25. return 0;
  26. }
  27. }
  28. for(int z = 0; z < i; z++) {
  29. pairs.insert(a[z] + a[i]);
  30. }
  31. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:2: error: expected unqualified-id before ‘for’
  for(int j = 0; j < n; j++) {
  ^~~
prog.cpp:2:17: error: ‘j’ does not name a type
  for(int j = 0; j < n; j++) {
                 ^
prog.cpp:2:24: error: ‘j’ does not name a type
  for(int j = 0; j < n; j++) {
                        ^
prog.cpp:19:1: error: ‘set’ does not name a type
 set<int> pairs; // pairs up to i-1
 ^~~
prog.cpp:20:1: error: expected unqualified-id before ‘for’
 for(int i = 0; i < n; i++) {
 ^~~
prog.cpp:20:16: error: ‘i’ does not name a type
 for(int i = 0; i < n; i++) {
                ^
prog.cpp:20:23: error: ‘i’ does not name a type
 for(int i = 0; i < n; i++) {
                       ^
stdout
Standard output is empty