|
| 1 | +#include <cmath> |
| 2 | +#include <set> |
| 3 | +#include <list> |
| 4 | +#include <unordered_set> |
| 5 | +#include <hash_map> |
| 6 | +#include <climits> |
| 7 | +#include <queue> |
| 8 | +#include <vector> |
| 9 | +#include <map> |
| 10 | +#include <set> |
| 11 | +#include <cstdlib> |
| 12 | +#include <fstream> |
| 13 | +#include <iomanip> |
| 14 | +#include <iostream> |
| 15 | +#include <sstream> // istringstream buffer(myString); |
| 16 | +#include <stack> |
| 17 | +#include <algorithm> |
| 18 | +#include <cstring> |
| 19 | +#include <cassert> |
| 20 | +using namespace std; |
| 21 | +#define bit(x,i) (x&(1<<i)) |
| 22 | +#define lowbit(x) ((x)&((x)^((x)-1))) |
| 23 | +//#define max(a,b) (a<b?b:a) |
| 24 | +//#define abs(x) (x<0?-x:x) |
| 25 | +#define IN(i,l,r) (l<i&&i<r) |
| 26 | +#define LINR(i,l,r) (l<=i&&i<=r) |
| 27 | +#define LIN(i,l,r) (l<=i&&i<r) |
| 28 | +#define INR(i,l,r) (l<i&&i<r) |
| 29 | +#define F(i,L,R) for (int i = L; i < R; i++) |
| 30 | +#define FE(i,L,R) for (int i = L; i <= R; i++) |
| 31 | +#define FF(i,L,R) for (int i = L; i > R; i--) |
| 32 | +#define FFE(i,L,R) for (int i = L; i >= R; i--) |
| 33 | +#define char2Int(c) (c-'0') |
| 34 | +#define lastEle(vec) vec[vec.size()-1] |
| 35 | +#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) |
| 36 | +#define clr(a,x) memset(a,x,sizeof(a)) |
| 37 | +#define getI(a) scanf("%d", &a) |
| 38 | +#define getII(a,b) scanf("%d%d", &a, &b) |
| 39 | +#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c) |
| 40 | +#define getS(x) scanf("%s", x); |
| 41 | +#define SZ(x) ((int)((x).size())) |
| 42 | +#define REMAX(a,b) (a)=max((a),(b)); |
| 43 | +#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl; |
| 44 | +#define REMIN(a,b) (a)=min((a),(b)); |
| 45 | +#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) |
| 46 | +#define ALL(t) t.begin(),t.end() |
| 47 | +#define ll long long |
| 48 | +#define ull unsigned long long |
| 49 | +#define ui unsigned int |
| 50 | +#define us unsigned short |
| 51 | +#define IOS ios_base::sync_with_stdio(0); |
| 52 | +#define pb push_back |
| 53 | +#define INF 1001001001 |
| 54 | +#define PI 3.1415926535897932384626 |
| 55 | +#define mp make_pair |
| 56 | +#define ll long long |
| 57 | +#define fi first |
| 58 | +#define se second |
| 59 | +#define wez(n) int (n); scanf("%d",&(n)); |
| 60 | +#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m)); |
| 61 | +#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k)); |
| 62 | +inline void pisz(int n) { printf("%d\n",n); } |
| 63 | +#define TESTS wez(testow)while(testow--) |
| 64 | +#define whileZ int T; getI(T); while(T--) |
| 65 | +#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ') |
| 66 | +#define printM(a,n,m) F(i,0,n){ F(j,0,m) cout << a[i][j] << ' '; cout << endl;} |
| 67 | +#define printV(a) printA(a,0,a.size()-1); |
| 68 | +#define printVV(a) F(i,0,a.size()) {F(j,0,a[i].size())cout << a[i][j] << ' '; cout << endl;} |
| 69 | +#define MAXN 10000 |
| 70 | +#define sz(a) int((a).size()) |
| 71 | +#define pb push_back |
| 72 | +#define all(c) (c).begin(),(c).end() |
| 73 | +#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++) |
| 74 | +#define present(c,x) ((c).find(x) != (c).end()) |
| 75 | +#define cpresent(c,x) (find(all(c),x) != (c).end()) |
| 76 | +typedef int elem_t; |
| 77 | +typedef vector<int> vi; |
| 78 | +typedef vector<vi> vvi; |
| 79 | +typedef pair<int,int> ii; |
| 80 | +template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";} |
| 81 | +template<typename T> ostream& operator<<(ostream &s,vector<T> t){F(i,0,SZ(t))s<<t[i]<<" ";return s; } |
| 82 | +int gcd(int a,int b){return a?gcd(b%a,a):b;} |
| 83 | +ll gcd(ll a,ll b){return a?gcd(b%a,a):b;} |
| 84 | +ll powmod(ll a,ll p,ll m){ll r=1;while(p){if(p&1)r=r*a%m;p>>=1;a=a*a%m;}return r;} |
| 85 | +const int fx[4][2] = {{0,1}, {1,0}, {0,-1}, {-1,0}}; |
| 86 | +using namespace std; |
| 87 | +struct TreeNode { |
| 88 | + int val; |
| 89 | + TreeNode *left; |
| 90 | + TreeNode *right; |
| 91 | + TreeNode(int x) : val(x), left(NULL), right(NULL) {} |
| 92 | +}; |
| 93 | + |
| 94 | +struct ListNode { |
| 95 | + int val; |
| 96 | + ListNode *next; |
| 97 | + ListNode(int x) : val(x), next(NULL) {} |
| 98 | +}; |
| 99 | + |
| 100 | +struct Interval { |
| 101 | + int start; |
| 102 | + int end; |
| 103 | + Interval() : start(0), end(0) {} |
| 104 | + Interval(int s, int e) : start(s), end(e) {} |
| 105 | +}; |
| 106 | + |
| 107 | +void printIntervals(vector<Interval> i){ |
| 108 | + F(j,0,i.size()){ |
| 109 | + cout << i[j].start << ' ' << i[j].end << endl; |
| 110 | + } |
| 111 | +} |
| 112 | +void printTree(TreeNode* cur){ |
| 113 | + if (cur == NULL) return; |
| 114 | + cout << cur->val << ' '; |
| 115 | + |
| 116 | + if (cur->left == NULL) cout << "NULL" << ' '; |
| 117 | + else { |
| 118 | + cout << cur->left->val << ' '; |
| 119 | + } |
| 120 | + |
| 121 | + if (cur->right == NULL) cout << "NULL" << endl; |
| 122 | + else { |
| 123 | + cout << cur->right->val << endl; |
| 124 | + } |
| 125 | + printTree(cur->left); |
| 126 | + printTree(cur->right); |
| 127 | +} |
| 128 | +void addNode(ListNode* &head, int x){ |
| 129 | + ListNode *a = new ListNode(x); |
| 130 | + if (head == NULL){ |
| 131 | + head = a; |
| 132 | + }else{ |
| 133 | + a->next = head; |
| 134 | + head = a; |
| 135 | + } |
| 136 | +} |
| 137 | +void printList(ListNode* head){ |
| 138 | + while(head != NULL){ |
| 139 | + cout << head->val << ' '; |
| 140 | + head = head->next; |
| 141 | + } |
| 142 | + cout << endl; |
| 143 | +} |
0 commit comments