1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| #include<bits/stdc++.h> #define fo(i,a,b) for(int i=a;i<=b;i++) using namespace std;
const int maxn=2005;
struct BST{ int i,cnt; }; bool operator < (const BST &a,const BST &b) {return a.cnt<b.cnt || a.cnt==b.cnt && a.i<b.i;}
int n,m,q; bitset<maxn> B[maxn],flp[maxn]; set<BST> S; set<pair<int,int>> Ans;
bitset<maxn> common; bool cmp(int x,int y) { common=B[x]&B[y]; return (common!=B[x] && common!=B[y]); }
void modify(int i,int cnt,int ty) { set<BST>::iterator it=S.find((BST){i,cnt}), mae, tsugi=it; tsugi++; if (it!=S.begin()) { mae=it; mae--; int x=mae->i, y=it->i; if (ty==-1) Ans.erase(make_pair(x,y)); else if (cmp(x,y)) Ans.insert(make_pair(x,y)); } if (tsugi!=S.end()) { int x=it->i, y=tsugi->i; if (ty==-1) Ans.erase(make_pair(x,y)); else if (cmp(x,y)) Ans.insert(make_pair(x,y)); } if (it!=S.begin() && tsugi!=S.end()) { int x=mae->i, y=tsugi->i; if (ty==1) Ans.erase(make_pair(x,y)); else if (cmp(x,y)) Ans.insert(make_pair(x,y)); } }
bitset<maxn> b1,b2; int main() { scanf("%d %d %d",&n,&m,&q); fo(i,1,n) S.insert((BST){i,0}); fo(i,1,m) flp[i]=flp[i-1], flp[i][i]=1; while (q--) { int a,l,r; scanf("%d %d %d",&a,&l,&r); int cnt=B[a].count(); modify(a,cnt,-1); S.erase((BST){a,cnt}); B[a]^=((flp[r]>>l)<<l); cnt=B[a].count(); S.insert((BST){a,cnt}); modify(a,cnt,1); if (Ans.empty()) puts("-1"); else { set<pair<int,int>>::iterator it=Ans.begin(); int x1=it->first, x2=it->second; common=B[x1]&B[x2]; b1=B[x1]^common, b2=B[x2]^common; int y1=b1._Find_first(), y2=b2._Find_first(); if (x1>x2) swap(x1,x2); if (y1>y2) swap(y1,y2); printf("%d %d %d %d\n",x1,y1,x2,y2); } } }
|